Recursive chmod

Sometimes you need to change the access control to files matching some requirement. E.g. today I needed grant execute access to the owner of all PHP scripts running under Apache HTTP Server, in a specific directory.

To do it, if you try the following command, you will not get the expected result:

chmod -R u+x *.php

The right way to do is using the following statement:

find . -name '*.php' -print0 | xargs -0 chmod u+x

So all files terminated by .php will have its mode changed. You also can use this command sequence to do other actions, like remove (rm), change owner (chown), move (mv) and so on. Another example, to remove all hidden files (name starts with a dot):

find . -name '.*' -print0 | xargs -0 rm -f
Advertisements

One thought on “Recursive chmod

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s