I just was wondering why suddenly all my files in a directory tree had the same chmod. After researching, I found out that a file existed which name was -R (in my case due to a mistyped wget-command). Here the steps to reproduce:
System: Ubuntu LTS 12.04.5 == Working: mkdir folder touch test touch folder/test ls -lR Output: | .: | insgesamt 4 | drwxr-xr-x 2 root root 4096 Nov 18 17:38 folder | -rw-r--r-- 1 root root 0 Nov 18 17:38 test | | ./folder: | insgesamt 0 | -rw-r--r-- 1 root root 0 Nov 18 17:38 test chmod 777 * ls -lR Output: | .: | insgesamt 4 | drwxrwxrwx 2 root root 4096 Nov 18 17:38 folder | -rwxrwxrwx 1 root root 0 Nov 18 17:38 test | | ./folder: | insgesamt 0 | -rw-r--r-- 1 root root 0 Nov 18 17:38 test == Strange behaviour: mkdir folder touch test touch folder/test ls -lR Output: | .: | insgesamt 4 | drwxr-xr-x 2 root root 4096 Nov 18 17:38 folder | -rw-r--r-- 1 root root 0 Nov 18 17:38 test | | ./folder: | insgesamt 0 | -rw-r--r-- 1 root root 0 Nov 18 17:38 test echo dummy > -R chmod 777 * ls -lR touch test Output: | .: | insgesamt 8 | drwxrwxrwx 2 root root 4096 Nov 18 17:57 folder | -rw-r--r-- 1 root root 6 Nov 18 17:57 -R | -rwxrwxrwx 1 root root 0 Nov 18 17:57 test | | ./folder: | insgesamt 0 | rwxrwxrwx 1 root root 0 Nov 18 17:57 test <---- this should not happen! I'm uncertain whether this is a chmod bug or not, as using ./* instead of * works as expected - it may also be expected. But on the other hand, having security-related commands like chmod doing different things depending on the files in the current directory seems to me also not to be the correct behaviour. BTW This above also applies to rm, which deletes all the files recursively if there is a file called -r in the directory (at least there is a sentence about files with leading "-", even no information that they make rm recursive ...) Thanks, Thomas
