Why will chmod 0000 directory-name not clear the special bits on the directory?

8

$ mkdir test 
$ chmod 0000 test 
$ ls -la | grep test | awk '{print $1}'
d---------.
$ chmod 6000 test
$ ls -la | grep test | awk '{print $1}'
d--S--S---.
$ chmod 0000 test
$ ls -la | grep test | awk '{print $1}'
d--S--S---.

I'm not sure why chmod 0000 test will not clear all of the permission bits. What am I not getting here? I've tried comparing with a calculator, and they do not match. The same behavior is seen on the server I have ssh'd into, RHEL, and my own machine, Ubuntu. I've been reading about this for a while and spending too much time trying to understand.

I ran into this problem when trying all the symbols for the first octal, having never used chmod with 4 octals before. It does seem to clear the sticky bit, however.

Leonardo

Posted 2014-10-06T03:16:24.483

Reputation: 197

Answers

8

0000 was considered ambiguous, since it might just mean 000, plus a leading zero since it's octal.

http://lists.gnu.org/archive/html/bug-coreutils/2011-03/msg00162.html

0755 is not explicit - it is ambiguous with people that are explicitly using printf %#3o to output a 3-digit octal string with leading 0 - I don't think we can change this.

That coreutils discussion thread starts with someone quoting the chmod man page noting this limitation:

you can set (but not clear) the bits with a numeric mode.

Nick Russo

Posted 2014-10-06T03:16:24.483

Reputation: 979