Permissions – Fix ‘sudo chmod -rwx’ Not Removing Group Write Permissions

chmodpermissions

I just ran the following command in a directory with several files, some owned by root, some by a normal user. I got a strange message:

$ sudo chmod -rwx *
chmod: example-file: new permissions are ----w----, not ---------

Why the heck does chmod refuse to clear all permissions, if a file had group write rights? What is the thought behind this behaviour?

And is there a way to force removing all permissions in one step, without having to execute sudo chmod g-w * afterwards?

Best Answer

From man chmod (emphasis mine):

A  combination  of the letters ugoa controls which users' access to the
file will be changed: the user who owns it  (u),  other  users  in  the
file's group (g), other users not in the file's group (o), or all users
(a).  If none of these are given, the effect is as if a were given, but
bits that are set in the umask are not affected.

This behaviour is working as intended, so, not a bug. See comments #4 and #5 in this bug report.

$ touch 1; ll
total 0
-rw-rw-r-- 1 muru muru 0 Jan  9 03:17 1
$ chmod -rwx *; ll
total 0
---------- 1 muru muru 0 Jan  9 03:17 1
$ umask
002
$ umask 072; chmod ug+rw *
$ chmod -rwx * 
chmod: 1: new permissions are ---rw----, not ---------
$ chmod a-rwx *; ll
total 0
---------- 1 muru muru 0 Jan  9 03:17 1

Don't be a lazy ass. Use a.

Related Question