Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 13 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
share|improve this answer
Excellent, thanks ErikA. – xtfer Nov 7 '10 at 7:17
You're welcome! – EEAA Nov 7 '10 at 7:20
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. – EEAA Nov 7 '10 at 13:37

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
share|improve this answer
Thanks, though it was the split between files or directories which was important. – xtfer Nov 9 '10 at 4:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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