Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

2 Answers 2

up vote 12 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
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
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

 
discard

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.