Monday, March 23, 2009

Recursive chmod on files or directories

This is useful when, for example, you need to set execute permissions on every PHP or Ruby file in all directories below your current directory.

Just replace the '*.php' with the name pattern you want to match. Works on Mac OS X 10.5.6.

find . -type f -name '*.php' -exec chmod 755 {} \;

To see which files will be changed use:

find . -type f -name '*.php' -exec echo {} \;

The {} braces are replaced with each filename as find finds each file that matches your pattern. To find directories use -type d.

1 comment:

Baljeet said...

Thanks. Recursive chmod was giving me trouble !