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”