On Tue, Nov 18, 2014 at 12:02 PM, operations <[email protected]> wrote: > 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 ...)
This isn't a bug in chmod, or anything else really, but rather the expected behavior of shell globbing. The parsing of the '*' on the command line is done by your shell, prior to the invocation of chmod. Therefore, chmod has no way to tell whether you typed -R, or it was expanded by the shell. As an example: $ ls -lR .: total 4 -rwxr-xr-x. 1 jstanley jstanley 0 Nov 18 12:54 -R drwxrwxr-x. 2 jstanley jstanley 4096 Nov 18 12:58 some-dir -rwxrwxrwx. 1 jstanley jstanley 0 Nov 18 12:54 some-file ./some-dir: total 0 -rw-rw-rw-. 1 jstanley jstanley 0 Nov 18 12:58 some-file $ echo * -R some-dir some-file As you can see from the 'echo *', the shell expanded it into '-R some-dir some-file'. Therefore, doing 'chmod *' is literally equivalent to typing 'chmod -R some-dir some-file' on the command line. Fortunately, chmod and other GNU utilities have a way to protect against this shell expansion - the '--' option, which indicates to stop processing further options on the command line and the remainder of the command line is arguments. For example, from the previous directory: $ chmod -- 755 * $ ls -lR .: total 4 -rwxr-xr-x. 1 jstanley jstanley 0 Nov 18 12:54 -R drwxr-xr-x. 2 jstanley jstanley 4096 Nov 18 12:58 some-dir -rwxr-xr-x. 1 jstanley jstanley 0 Nov 18 12:54 some-file ./some-dir: total 0 -rw-rw-rw-. 1 jstanley jstanley 0 Nov 18 12:58 some-file Notice how my 'some-dir/some-file' retains the mode that I originally had, 0666. Hope that helps! -Jon
