Skip to main content

chmod octal form of sgid/suid removal fails

The was a disturbance in the force today:

$ mkdir dir
$ touch file
$ chmod +s dir file
$ ls -l
drwsr-sr-x 2 root root 4096 Apr 30 11:54 dir
-rwSr-Sr-- 1 root root    0 Apr 30 11:54 file

$ chmod 0750 dir
$ chmod 0640 file
$ ls -l
drwsr-s--- 2 root root 4096 Apr 30 11:54 dir
-rw-r----- 1 root root    0 Apr 30 11:54 file
Yes, this is even documented behaviour and conforms to POSIX as well - still, I find it far from being intuitive. There's a quite an interesting posting at the bug-coreutils list, stating:
> This topic came up when I first added that feature, and originally I
> agreed with you, but others did not and their arguments were
> persuasive.  The counterargument is that it's strange if a leading
> zero changes the semantics of a number, as this is not what many
> people expect.
...mentioning an earlier discussion on the same list. Oh well...