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)
3 Answers
man 3 chmod
contains the information you are looking for.
chmod -R +r directory
the -R
option tells chmod
to operate recursively.
-
3Historicaly
-r
is for recursive operation and-R
is for dangerous recursive. If capitalizedR
is used forchmod
andchown
it's because we prefer to use more precise operation like usingfind
. See my answer!– F. HauriMay 9, 2014 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– insignFeb 24 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. HauriFeb 24 at 17:57
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
chmod -R 0444 ./folder_name
Apply the permission to all the files under a directory recursively
bash
tag. But, it's just a comment, right?