Super User is a question and answer site for computer enthusiasts and power users. 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 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
up vote 8 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

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
find somepath \( -type f -exec chmod a=r {} \; \) -o \( -type d -exec chmod a=rx {} \; \)
share|improve this answer

You must log in to answer this question.

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