I would like to change the permissions of a folder and all its subfolders 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 Stack Overflow question too:
Best Solution
The other answers are correct, in that
chmod -R 755will 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
findcommand. For example:To change all the directories to 755 (
drwxr-xr-x):To change all the files to 644 (
-rw-r--r--):Some splainin': (thanks @tobbez)
chmod 755 {}specifies the command that will be executed byfindfor each directorychmod 644 {}specifies the command that will be executed byfindfor each file{}is replaced by the path;the semicolon tellsfindthat this is the end of the command it's supposed to execute\;the semicolon is escaped, otherwise it would be interpreted by the shell instead offind