Recursively change directory permissions

Needed to make all directories in a hierarchy executable so a newly applied group could traverse the tree.


I really hate it when someone does a chmod -R 777 * on a directory tree. Particularly since there is some software out there that isn’t amused by those kinds of antics (e.g. sendmail, Oracle’s Internet Directory, etc.).

There is a more surgical way to set permissions by combining the find and chmod commands.

For example, this one-liner will set all directories under it to executable for the owner group, allowing members to drill down into it:

find . -type d -exec chmod g+x {} ;

A variation on this would be to strip the executable bit from all files in a tree that don’t need it:

find /data/code -name "*.php" -type f -exec chmod ugo-x {} ;

These techniques can come in handy when repairing directory permissioning that has been botched up through carelessness or panic, or in revising permissions to allow or deny access as needed.