I have to change the permissions of the htdocs
directory in apache to a certain group and with certain read/write/execute.
The directories need to have 775 permissions and the files need to have 664.
If I do a recursive 664 to the htdocs
, then all files and directories will change to 664.
I don't want to change the directories manually.
Is there any way to change only files or directories?
Use find's
-type
option to limit actions to files and directories. Use the-o
option to specify alternate actions for different types, so you only have to runfind
once, rather than separately for each type.try:
I use something similar to the solution provided by Gordon:
It should always set 775 for folders and 664 for files, even if the execute permission was previosly set for some file
Gordon's answer above is correct, but if you're trying to lock down access to a directory tree, it leaves scripts that are executable to the owner also executable to whoever has been granted the capital X.
Using
or
is safer.
chmod
can actually do this itself; theX
symbolic permission means "execute, if it makes sense" which generally means on directories but not files. So, you can use:The only potential problem is that if any of the plain files already have execute set,
chmod
assumes it's intentional and keeps it.Use
find
to search for directories and apply chmod on them:Use type
f
for file: