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.
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.
There's also a exec parameter in find that will do the same:
find . -name filename -exec chmod 755 {} \;
find
supports it, you can use a +
instead of the \;
to get xargs
-like functionality.
Jan 18, 2010 at 18:46
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.
filename