20111221 recursively change directory permissions - plembo/onemoretech GitHub Wiki

title: Recursively change directory permissions link: https://onemoretech.wordpress.com/2011/12/21/recursively-change-directory-permissions/ author: lembobro description: post_id: 1863 created: 2011/12/21 17:52:14 created_gmt: 2011/12/21 21:52:14 comment_status: closed post_name: recursively-change-directory-permissions status: publish post_type: post

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.

Copyright 2004-2019 Phil Lembo