5

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?

  • shouldn't it be a-rwx? – cat Jan 8 '16 at 21:50
  • FYI: I don't care about swearing. "Why the heck refuses chmod" is ungrammatical. – muru Jan 8 '16 at 21:56
  • @muru I have to admit you were right. Now it's better! ;-) – Byte Commander Jan 8 '16 at 21:58
6

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.

  • "but bits that are set in the umask are not affected" - Could you explain that with another sentence, please? – Byte Commander Jan 8 '16 at 21:55
  • @ByteCommander it should be clear enough if you look at the example (note where I change umask and what I change it to). – muru Jan 8 '16 at 21:55
  • Ah, now I understand it. I did not notice that root has a different umask (022 instead of normal users' 002) by default. Thanks. Remember me to upvote tomorrow. My daily limit is already reached. – Byte Commander Jan 8 '16 at 22:02
  • What is strange is that when chmod follows umask (i.e. when ugoa are not given), it exits with code 1, as if unsuccessful. – Ruslan May 22 '17 at 10:05
  • @muru Your claim that "This behavior is POSIX-mandated" is incorrect. POSIX Application Usage text is non-normative and is therefore not mandated by POSIX. – fpmurphy Mar 11 '18 at 5:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.