Friday 31 October 2014

Linux: Change permissions recursively of only directories or only files

For directories:

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

For files:

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

Another way:

find /path/to/base/dir -type d -exec chmod 755 {} +
find /path/to/base/dir -type f -exec chmod 644 {} + 

http://superuser.com/questions/91935/how-to-chmod-755-all-directories-but-no-file-recursively

However, this seems to be the best solution, when you do not need to unset execute permissions on files:


chmod -R u+rwX,go+rX,go-w /path
The important thing to note here is that X acts differently to x - the man page says The execute/search bits if the file is a directory or any of the execute/search bits are set in the original (unmodified) mode. In other words, chmod u+X on a file won't set the execute bit; and g+X will only set it if it's already set for the user.

No comments:

Post a Comment