tags:

views:

623

answers:

4

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

+2  A: 

via http://www.linuxquestions.org/questions/aix-43/chmod-recursion-files-only-208798/?s=a70210fb5e5d0aa7d3c69d8e8e64e3ed

"find . -type f -print | xargs chmod 444 "shoud work, isn't it ? If not, find . -print >myfile.sh and vi myfile.sh removing the directories (they should not be soo many), and then 1,$s/^/chmod 444/ and sh myfile.sh.

b0x0rz
+3  A: 

This is another way to do this using find:

find . -type f -exec chmod 644 {} \;
Stephen C
+6  A: 

@StephenC's is a good answer (find -exec) but 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. Using xargs will batch up the file names into large groups before running a sub-process for that group.

@b0x0rz's is also good unless you have filenames with embedded spaces or newlines (heinous though they are).

A solution that solves both these problems is (assuming you have a decent enough find and xargs):

find . -type f -print0 | xargs -0 chmod 644

The -print0 causes find to terminate the file names with a NUL character and you have to notify xargs of that fact as well (-0).

paxdiablo
This is great for GNU find but unfortunately -print0 and xargs -0 are not standard, and don't work e.g. on Solaris. So in that case use one of the other solutions.
mark4o
A: 

with GNU find

find /path -type f -exec chmod 644 {} +;

ghostdog74