18

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?

2
  • 1
    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, 2010 at 8:00
  • If that's intended to be an answer then it should be in an answer. Oct 5, 2010 at 8:07

4 Answers 4

18

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.

8
  1. chmod accepts mode X, which only sets x to directories. a=X

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

2
  • 3
    +1 for option #2, the most logical way Oct 5, 2010 at 8:56
  • 3
    +1 for option 2 also, but -0.5 for misunderstanding what capital X means in chmod Oct 5, 2010 at 11:30
7

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

You must log in to answer this question.

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