Skip to main content

exec option using "find"

"exec" can be used along with "find" in order to pass on a command to be applied to the output. This can be used for example for changing permissions of code files under a directory path.


This helps to remove subversion control files from a directory (and all it's sub-directories)
find . -type d -name '.svn' -exec rm -rf {} \;

This helps to keep your directory permissions clean
find public_html -type d -exec chmod 755 {} \;


Practical Use

These 2 commands in a script will help secure your web-folder

ashant@washington:~/bin$ more secure_webfolders
sudo /usr/bin/find $1 -type f -name '*.php' -exec chmod 644 {} \;
sudo /usr/bin/find $1 -type d -exec chmod 755 {} \;