Hello,

If you try to rename a file with the -n flag while keeping the same name, mv
reports that no replacement occurred in GNU/Linux, while mv reports nothing
in GNU/Hurd:

user@user:~$ > file
user@user:~$ stat file
  File: file
  Size: 0             Blocks: 0          IO Block: 4096   regular empty file
Device: 259,2    Inode: 10131664    Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/    user)   Gid: ( 1000/ user)
Access: 2026-09-08 10:58:30.443730136 +0700
Modify: 2026-09-08 10:58:30.443730136 +0700
Change: 2026-09-08 10:58:30.443730136 +0700
 Birth: 2026-09-08 10:58:30.443730136 +0700
user@user:~$
user@user:~$ mv -n file file
mv: not replacing 'file'
user@user:~$ stat file
  File: file
  Size: 0             Blocks: 0          IO Block: 4096   regular empty file
Device: 259,2    Inode: 10131664    Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/    user)   Gid: ( 1000/ user)
Access: 2026-09-08 10:58:30.443730136 +0700
Modify: 2026-09-08 10:58:30.443730136 +0700
Change: 2026-09-08 10:58:30.443730136 +0700
 Birth: 2026-09-08 10:58:30.443730136 +0700


demo@debian:~$ > file
demo@debian:~$ stat file
  File: file
  Size: 0             Blocks: 0          IO Block: 8192   regular empty file
Device: 0,8    Inode: 139592    Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/    demo)   Gid: ( 1000/ demo)
Access: 2026-09-08 05:00:28.000000000 +0100
Modify: 2026-09-08 05:00:28.000000000 +0100
Change: 2026-09-08 05:00:28.000000000 +0100
 Birth: 2026-09-08 05:00:28.000000000 +0100
demo@debian:~$
demo@debian:~$ mv -n file file
demo@debian:~$ stat file
  File: file
  Size: 0             Blocks: 0          IO Block: 8192   regular empty file
Device: 0,8    Inode: 139592    Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/    demo)   Gid: ( 1000/ demo)
Access: 2026-09-08 05:00:28.000000000 +0100
Modify: 2026-09-08 05:00:28.000000000 +0100
Change: 2026-09-08 05:00:28.000000000 +0100
 Birth: 2026-09-08 05:00:28.000000000 +0100

Since the file's stat doesn't change, I assume mv isn't performing any
manipulations on the file and simply doesn't report that no replacement
occurred.  As far as I can tell, this is because the copy_internal function
from coreutils/src/copy.c handles this error differently.

Is this behavior desirable?

Thanks,

--
Mikhail Karpov


Reply via email to