How to apply CHMOD command to any file with a specific name recursively in Linux?

Solution 1:

This will find all files named filename, recursively from the current directory, and pass them to chmod.

find -name filename | xargs chmod 755

See the manpages for find and xargs for more advanced options. In particular, look at the -print0 flag and corresponding -0 to xargs if you get errors about files with spaces in the name.

Solution 2:

There's also a exec parameter in find that will do the same:

find . -name filename -exec chmod 755 {} \;

Solution 3:

You can get the best of both worlds if you use the + operator to find to make it run chmod on many files at once.

find . -name filename -exec chmod 755 '{}' +

You should always put a ' around your {}, otherwise a filename with a space in it could mess things up. In this case it's not a problem, but I have a habit of doing it.