5

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?

2 Answers 2

13

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
2
  • 3
    find ... -print0 | xargs -0 ... in case there are spaces or newlines in filenames. Nov 7, 2010 at 8:19
  • Excellent, thanks for the correction, Dennis. Edited accordingly.
    – EEAA
    Nov 7, 2010 at 13:37
3

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .