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?

up vote 13 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.

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

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

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

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.