How can I recursively set read-only permissions?

14

3

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?

David B

Posted 2010-10-05T07:54:47.963

Reputation: 1 974

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 – 2010-10-05T08:00:42.940

If that's intended to be an answer then it should be in an answer. – Ignacio Vazquez-Abrams – 2010-10-05T08:07:02.037

Answers

13

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

Posted 2010-10-05T07:54:47.963

Reputation: 1 974

7

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

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

user1686

Posted 2010-10-05T07:54:47.963

Reputation: 283 655

3+1 for option #2, the most logical way – Matteo Riva – 2010-10-05T08:56:12.430

3+1 for option 2 also, but -0.5 for misunderstanding what capital X means in chmod – Doug Harris – 2010-10-05T11:30:27.297

3

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 {} \;

Odd Erik Paulsen

Posted 2010-10-05T07:54:47.963

Reputation: 31

1

find somepath \( -type f -exec chmod a=r {} \; \) -o \( -type d -exec chmod a=rx {} \; \)

Ignacio Vazquez-Abrams

Posted 2010-10-05T07:54:47.963

Reputation: 100 516