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?


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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