Selectively set 'execute' permission for directories.

Mon 02 June 2014 by Mikhail Basov

Task:

Recursively change permissions:
user:
rwx - for directories
rw - for files
group:
rx - for directories
r - for files
other:
rx - for directories
r - for files

Solution:

chmod -R u+rwX,go+rX,go-w /directory

Explanation:

Quote from HP-UX chmod man page about 'X' (capital X) option:

X    Conditionally add or delete the
     execute/search permission as follows:
         +  If file is a directory, add or delete
            the search permission to the existing
            file mode for who.  (Same as x.)
         +  If file is not a directory, and the
            current file permissions include the
            execute permission (ls -l displays an x
            or an s) for at least one of user,
            group, or other, then add or delete the
            execute file permission for who.
         +  If file is not a directory, and no
            execute permissions are set in the
            current file mode, then do not change
            any execute permission.

Comments