Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

How to change permissions for a folder and its subfolders/files in one step in Linux?

I want 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?
by

2 Answers

Kajalsi45d
Check the - R alternative
chmod -R <permissionsettings> <dirname>

Later on, you can save a great deal of time by checking the man page first:
man <command name>

So for this situation:
man chmod
sandhya6gczb
if you want to change permissions of all files and directories at once.
use
chmod -R 755 /opt/lampp/htdocs

if the number of files you are using is very large. Use

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

Otherwise use

chmod 755 $(find /path/to/base/dir -type d)

Login / Signup to Answer the Question.