Marc Blase

How to CHMOD web files properly

To change all the directories to 755 (-rwxr-xr-x):

find /path/to/web/dir -type d -exec chmod 755 {} \;

To change all the files to 644 (-rw-r–r–):

find /path/to/web/dir -type f -exec chmod 644 {} \;

chmod 644 {} \; specifies the command that will be executed by find for each file. {} is replaced by the file path, and the semicolon denotes the end of the command (escaped, otherwise it would be interpreted by the shell instead of find).

or alternatively, you could do the following:

chmod -R a+rX ./*

The X (that is capital X, not small x!) is ignored for files (unless they are executable for someone already) but is used for directories.

Thanks for the answers once again Stack Overflow.

Published on January 15, 2014