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

bashcommand-line-interfacelinuxUbuntu

I need to know how to apply a CHMOD command to only files that have a specific name recursively?

chmod 755 -R filename

Something like above but it should apply to any filename that exists in any sub folders.

Best Answer

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.