I have a folder consisting of a mix of files and subdirectories, on OS X. I'm looking for a one-line script to set the execute permission bit only on all subfolders/subdirectories, without setting all the normal files to executable as well.
The usual chmod -R would set execute on everything.
Use the special permission X
- yliu on August 07, 2011, 10:10 AM UTC
So instead of using (for example) chmod -R g+rx ., use
The capitalized X sets the executable bit only if the target is a directory. Per the man page:
So you can't use it to remove executable bits on directories, but definitely can use it to set the executable permission bit.
chmod -R g+rX .
The capitalized X sets the executable bit only if the target is a directory. Per the man page:
The execute/search bits if the file is a directory or any of the execute/search bits are set in the original (unmodified) mode. Operations with the perm symbol ``X'' are only meaningful in conjunction with the op symbol ``+'', and are ignored in all other cases.
So you can't use it to remove executable bits on directories, but definitely can use it to set the executable permission bit.