How to Recursively Change Permissions, Only Files / Directories, Chmod
Sometimes we have the need to recursively change the permissions, but only for either files or directories. Here’s a handy way to do this, from the command line.
*Note: Being recursive, these are powerful commands, and can change a whole bunch of things, in a very short amount of time. Please do make sure to think it through before running things like these.
To Recursively Give Directories Read & Execute Privileges:
find /path/to/base/dir -type d -exec chmod 755 {} +
To Recursively Give Files Read Privileges (But Not Execute or Write):
find /path/to/base/dir -type f -exec chmod 644 {} +
Both of the above can be tailored to suit your particular needs.
Or, if there are many objects to process:
chmod 755 $(find /path/to/base/dir -type d)
chmod 644 $(find /path/to/base/dir -type f)
Or, to reduce chmod
spawning:
find /path/to/base/dir -type d -print0 | xargs -0 chmod 755
find /path/to/base/dir -type f -print0 | xargs -0 chmod 644
See also:
http://superuser.com/questions/91935/how-to-chmod-755-all-directories-but-no-file-recursively