4

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
/bin/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?

5
  • Somewhat related: What is the point of mv -f
    – user6860
    Commented Oct 19, 2015 at 10:16
  • 2
    Can't reproduce. What does ls -l /proc/self/fd/0 output? Commented Oct 19, 2015 at 10:59
  • Are you root? Is the file writable to you by some other means like ACLs ([ -w 2 ] && echo yes outputs yes)? Commented Oct 19, 2015 at 11:04
  • 1
    You don't have an alias on mv? Are you sure you're running /bin/mv ?
    – PM 2Ring
    Commented Oct 19, 2015 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
    Commented Oct 19, 2015 at 11:35

1 Answer 1

5

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.

2
  • 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) ? Commented Oct 19, 2015 at 14:40
  • @MarkPlotnick, that return value is 0.
    – user6860
    Commented Oct 19, 2015 at 17:22

You must log in to answer this question.