The GNU Coreutils manual for mv says:

If a destination file exists but is normally unwritable, standard input is a terminal, and the -f or --force option is not given, mv prompts the user for whether to replace the file. (You might own the file, or have write permission on its directory.) If the response is not affirmative, the file is skipped.

However, the version of mv I am using (GNU coreutils 8.21 on Ubuntu 14.04.3 LTS) exhibits unexpected behaviour:

$ which mv
$ ls -l
total 0
$ echo foo > 1; chmod -w 1; cp 1 2; ls -l | cut -d' ' -f 1-5,9
-r-x------ 1 me me 4 1
-r-x------ 1 me me 4 2
$ echo bar > 2
-bash: 2: Permission denied
$ mv 1 2
$ ls -l | cut -d' ' -f 1-5,9
-r-x------ 1 me me 4 2

Based upon the manual excerpt quoted above, I would have expected the mv 1 2 command to have prompted the user before overwriting file 2.

Is there a bug in my version of mv, or a bug in my understanding? If the latter, then what does the manual mean?

  • Somewhat related: What is the point of mv -f – user6860 Oct 19 '15 at 10:16
  • 2
    Can't reproduce. What does ls -l /proc/self/fd/0 output? – Stéphane Chazelas Oct 19 '15 at 10:59
  • Are you root? Is the file writable to you by some other means like ACLs ([ -w 2 ] && echo yes outputs yes)? – Stéphane Chazelas Oct 19 '15 at 11:04
  • 1
    You don't have an alias on mv? Are you sure you're running /bin/mv ? – PM 2Ring Oct 19 '15 at 11:04
  • Thanks. Your various helpful comments reminded me: I've been burned by unexpected behaviour, related to permissions, on this particular server once before. – user6860 Oct 19 '15 at 11:35

Turns out, the server was using a file system of type "cifs" (presumably the Common Internet File System, aka CIFS). This was discovered by running the command df -T.

CIFS apparently exhibits unconventional behaviour with respect to permissions.

Running the same commands on a machine with an ext4 file system and a recent version of Coreutils yielded:

$ mv 1 2
mv: replace ‘2’, overriding mode 0444 (r--r--r--)?

as expected.

  • Interesting. If you do strace -e access mv 1 2 on the CIFS filesystem, what is the return value that it shows for access("2", W_OK) ? – Mark Plotnick Oct 19 '15 at 14:40
  • @MarkPlotnick, that return value is 0. – user6860 Oct 19 '15 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy