I want to make all files (and directories) under a certain directory world readable without having to chmod each file on its own. it would be great if there is an option to also do this recursively (look under folders and chmod 666 all files under it)
Asked
Active
Viewed 7.8k times
45
-
1@PedroRomano How do you know this one is not for writing a Bash script? – Oct 29 '12 at 09:56
-
@H2CO3: Doesn't seem to fall under [What kind of questions can I ask here?](http://stackoverflow.com/faq#questions). Doesn't mention _Bash_ anywhere in the title or text. Doesn't have a `bash` tag. But, it's just a comment, right? – Pedro Romano Oct 29 '12 at 10:00
-
1@Rorchackh do you want to make readable **files only** and exclude directories, or did you mean "all entries in the directory" when you wrote "all files"? I think the later one applies. – Oct 29 '12 at 10:02
-
everything inside a directory. That includes sub directories. – Rorchackh Oct 29 '12 at 10:03
3 Answers
58
man 3 chmod
contains the information you are looking for.
chmod -R +r directory
the -R
option tells chmod
to operate recursively.

The Unfun Cat
- 29,987
- 31
- 114
- 156
-
3Historicaly `-r` is for *recursive* operation and `-R` is for *dangerous recursive*. If capitalized `R` is used for `chmod` and `chown` it's because we prefer to use more precise operation like using `find`. See my answer! – F. Hauri - Give Up GitHub May 09 '14 at 16:45
-
I'm certainly appreciate you answer but it is a little bit hard to understand even to me which I'm not a newbie. @F.Hauri – insign Feb 24 '22 at 17:32
-
@insign Changing rights recursively could be dangerous! you coud for sample .1 *break some system requirment*, .2 *expose private files*... Reverting wrong manip from there could be very tricky. – F. Hauri - Give Up GitHub Feb 24 '22 at 17:57
12
As a directory could contain links and/or bind mounts, the use of find
could ensure a finest granularity in what to do and what to not do....
find directory \( -type f -o -type d \) -print0 |
xargs -0 chmod ugo+r
To exclude paths under mount points:
find directory -mount \( -type f -o -type d \) -print0 |
xargs -0 chmod ugo+r
To exclude some specific files (.htaccess for sample):
find directory \( -type f -o -type d \) ! -name '.htaccess' -print0 |
xargs -0 chmod ugo+r

F. Hauri - Give Up GitHub
- 64,122
- 17
- 116
- 137
2
chmod -R 0444 ./folder_name
Apply the permission to all the files under a directory recursively

0x90
- 39,472
- 36
- 165
- 245