How can I recursively set read-only permissions?

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?


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