I want to set my folders permissions to 555 and my files permissions to 554, so I tried the following chmod:

sudo chmod -R -v ug=rx,o=r,a+X mydir/

I thought this would set the user and group permissions to r-x and others permission to r--, but since there is an a+X only folders would receive an r-x for the others permission, but files would remain r--.

But this isn't working and it is setting all the files and folders to 555, even if I set all folders and files to 444 before to assure there isn't any x permission anywhere.

Why this chmod command doesn't work as I expected it to?


Ok, I found the answer here on wikipedia:

When it explains about the X option:

...It applies execute permissions to directories regardless of their current permissions and applies execute permissions to a file which already has at least one execute permission bit already set (either owner, group or other)...

I really can't understand why anyone would want to apply an x permission on any user (owner, group or other) if another user already have this permission already...or in another words, give others execute permission if owner has it, but someone saw this as the best default behavior and that's how it works, go figure.

I changed my code to:

chmod -R ugo=r,a+X,ug+x

since order matters, now it will behave as expected.

  • 1
    Just read man chmod, it's all in there... – heemayl May 10 '17 at 3:19
  • I read it, and it says execute/search only if the file is a directory or already has execute permission for some user (X), which I thought it meant only for the same user as this was the only thing that made sense in my head – mFeinstein May 10 '17 at 3:31

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