I'm a bit puzzled about the following behavior (Linux, Debian 8.3, ext2 filesystem)
test@linux:~$ ls -ld directory/ file
drwxr-xr-x 2 root root 4096 Mar 10 18:51 directory/
-rw-r--r-- 1 root root 8 Mar 10 18:51 file
test@linux:~$ ls -ld target_directory/
drwxr-xr-x 2 test test 4096 Mar 10 18:47 target_directory/
test@linux:~$ mv file target_directory/
test@linux:~$ mv directory/ target_directory/
mv: cannot move ‘directory/’ to ‘target_directory/directory’: Permission denied
And that's even the case if directory/
is empty. Funny: rmdir directory/
works in that case.
Why? It would be nice to know why mv
behaves so differently for a file and a directory, that both don't have write permissions.
Actually in the vein of "give a man a fish...", don't hesitate to point me to a book which explains this and the permissions system correctly because (mini-rant) I constantly see stuff like that (from a well-known Linux book):
$ ls -ld ch3 test -rw-rw-r-- 1 joe sales 4983 Jan 18 22:13 ch3 drwxr-xr-x 2 joe sales 1024 Jan 24 13:47 test
The first line shows that the
ch3
file has read and write permission for the owner and the group. All other users have read permission, which means they can view the file but cannot change its contents or remove it.
PS/Warning: Yes, the description in the passage above is factually wrong. Don't tell me that or "correct" the post. I just quoted it here to illustrate how much half-knowledge about this issue is floating around.