Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Linux by (18.4k points)
recategorized by

I would like to change the permissions of a folder and all its subfolders and files in one step (command) in Linux.

I have also tried the below command but it works only for the specified folder:

The chmod 775 /opt/lampp/htdocs

Is there any way to set the

 chmod 755 for /opt/lampp/htdocs

and all of the content including the subfolders and files?

Also, in the future, I have to create my new folder or file inside this htdocs, how can these permissions of that automatically be set to 755?

1 Answer

0 votes
by (36.8k points)

The other answers are correct, in the chmod -R 755 will set the permissions to all the files and subfolders in a tree. It might make sense for these directories, but why set a execute bit on all files?

I suspect what you want to do is set some directories to 755 and either leave these files alone or set them to 644. For this, you can use this find command. For example:

To change all these directories to 755 (drwxr-xr-x):

find /opt/lampp/htdocs -type d -exec chmod 755 {} \;

To change all these files to 644 (-rw-r--r--):

find /opt/lampp/htdocs -type f -exec chmod 644 {} \;

Come and join Linux training to gain great knowledge. 

Do check out the video below

 

 

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jan 16, 2021 in Linux by supriya (36.8k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...