Using ‘find’ to quickly change file permissions

To quickly change UNIX/Linux file permissions (this applies to Mac OS X also), one can use the find command, combined with the -exec flag.

For example, suppose you want all directories nested beneath (and including) the current directory to have 755 permissions:

find . -type d -exec chmod 755 ‘{}’ ;

Explanation: ‘.’ refers to the current directory, ‘-type d’ indicates file type of directory, the command executed is chmod 755, where ‘{}’ is a cookie — the directory name will be inserted here. The exec command ends with a semicolon ‘;’, which must be escaped with a backslash so that your shell doesn’t interpret it.

To change file permissions to 644 (leaving the directories as is):

find . -type r -exec chmod 644 ‘{}’ ;

Note the type of ‘r’ to indicate a regular file.

Using these two find commands together, one can quickly change permissions on directories and files to 755 and 644 respectively to make them globally accessible, or 700 and 600 respectively to secure the files.