I would like to change permissions of a folder and all its sub folders and files in one step (command) in Linux.
I have already tried the below command but it works only for the mentioned folder:
chmod 775 /opt/lampp/htdocs
Is there a way to set chmod 755
for /opt/lampp/htdocs
and all of its content including subfolders and files?
Also, in the future, if I create a new folder or file inside htdocs
, how can the permissions of that automatically be set to 755
?
I had a look at this link too:
http://stackoverflow.com/questions/3740187/how-to-set-default-chmod-in-linux-terminal
Answer
The other answers are correct, in that chmod -R 755
will set these permissions to all files and subfolders in the tree. But why on earth would you want to? It might make sense for the directories, but why set the execute bit on all the files?
I suspect what you really want to do is set the directories to 755 and either leave the files alone or set them to 644. For this, you can use the find
command. For example:
To change all the directories to 755 (drwxr-xr-x
):
find /opt/lampp/htdocs -type d -exec chmod 755 {} \;
To change all the files to 644 (-rw-r--r--
):
find /opt/lampp/htdocs -type f -exec chmod 644 {} \;
No comments:
Post a Comment