I'm trying to set permissions/ownership on either directories or files, recursively within a given directory, without changing the other.

E.g. I have directory /web where I want to set all the directories to 775, but the files to 664.

Is there a way to do this easily?

link|improve this question
feedback

2 Answers

up vote 11 down vote accepted

For files:

$ find /path/to/directory -type f -print0 | xargs -0 chmod 664

For directories:

$ find /path/to/directory -type d -print0 | xargs -0 chmod 775
link|improve this answer
Excellent, thanks ErikA. – xtfer Nov 7 '10 at 7:17
You're welcome! – ErikA Nov 7 '10 at 7:20
3  
find ... -print0 | xargs -0 ... in case there are spaces or newlines in filenames. – Dennis Williamson Nov 7 '10 at 8:19
Excellent, thanks for the correction, Dennis. Edited accordingly. – ErikA Nov 7 '10 at 13:37
feedback

As a supplement to ErikA's answer, if I were to guess the reason you wanted to do this, you were looking to add the write bit for "group". If that's the case, you can avoid the two-command dance and just run:

chmod -R g+w /path/to/directory
link|improve this answer
Thanks, though it was the split between files or directories which was important. – xtfer Nov 9 '10 at 4:16
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.