Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a very large and deep directory. I would like to make all of it read only. The problem is I guess I have to distinguish between files (which will get a=r) and directories (which will get a=rx).

How can I do that?

share|improve this question
    
I just found this: chmod a=rX which solves my problem. From the man: (X) execute/search only if the file is a directory or already has execute permission for some user –  David B Oct 5 '10 at 8:00
    
If that's intended to be an answer then it should be in an answer. –  Ignacio Vazquez-Abrams Oct 5 '10 at 8:07

4 Answers 4

up vote 7 down vote accepted

I just found this: chmod a=rX which solves my problem. From the man: (X) execute/search only if the file is a directory or already has execute permission for some user.

share|improve this answer
  1. chmod accepts mode X, which only sets x to directories. a=X

  2. You can also just remove the write permission: a-w

share|improve this answer
1  
+1 for option #2, the most logical way –  Matteo Riva Oct 5 '10 at 8:56
1  
+1 for option 2 also, but -0.5 for misunderstanding what capital X means in chmod –  Doug Harris Oct 5 '10 at 11:30
find somepath \( -type f -exec chmod a=r {} \; \) -o \( -type d -exec chmod a=rx {} \; \)
share|improve this answer

The suggestions above did not work for me, all folders were set read-only.
A colleague gave me this, which works:

find . -type f -exec chmod a-w {} \;
share|improve this answer

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.