I need to use chmod to change all files recursivly to 664. I would like to skip the folders.
I was thinking of doing something like this
ls -lR | grep ^-r | chmod 664
This doesn't work, I'm assuming because I can't pipe into chmod
Anyone know of an easy way to do this?
Thanks
Best Solution
A
find -exec
answer is a good one but it suffers from the usually irrelevant shortcoming that it creates a separate sub-process for every single file. However it's perfectly functional and will only perform badly when the number of files gets really large. Usingxargs
will batch up the file names into large groups before running a sub-process for that group of files.You just have to be careful that, in using
xargs
, you properly handle filenames with embedded spaces, newlines or other special characters in them.A solution that solves both these problems is (assuming you have a decent enough
find
andxargs
implementation):The
-print0
causesfind
to terminate the file names on its output stream with a NUL character (rather than a space) and the-0
toxargs
lets it know that it should expect that as the input format.