Change directory with cd command to the desired location under with you need to all directories to 755, and all files to 644 permissions. Then use first command to chmod 755 for all directories and sub directories. The second command will change all the files permission to 0644 (chmod 644) under the directory tree.
To set the permission to 755, run the following chmod command. What if the directory contains one or more sub-directories? To apply chmod 755 to all the subsequent files and directories, run chmod in recursive mode. Verify the changes using the ls command.
Some file permission examples: 777 - all can read/write/execute (full access). 755 - owner can read/write/execute, group/others can read/execute. 644 - owner can read/write, group/others can read only.
To modify the permission flags on existing files and directories, use the chmod command ("change mode"). It can be used for individual files or it can be run recursively with the -R option to change permissions for all of the subdirectories and files within a directory.
One approach could be using find:
find /desired_location -type d -print0 | xargs -0 chmod 0755
find /desired_location -type f -print0 | xargs -0 chmod 0644
The easiest way is to do:
chmod -R u+rwX,go+rX,go-w /path/to/dir
which basically means:
to ch
ange file mod
es -R
ecursively by giving:
u
ser: r
ead, w
rite and eX
ecute permissions,g
roup and o
ther users: r
ead and eX
ecute permissions, but not -w
rite permission.Please note that X
will make a directory executable, but not a file, unless it's already searchable/executable.
+X
- make a directory or file searchable/executable by everyone if it is already searchable/executable by anyone.
Please check man chmod
for more details.
See also: How to chmod all directories except files (recursively)? at SU
The shortest one I could come up with is:
chmod -R a=r,u+w,a+X /foo
which works on GNU/Linux, and I believe on Posix in general (from my reading of: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/chmod.html).
What this does is:
Importantly, the step 1 permission clears all execute bits, so step 3 only adds back execute bits for directories (never files). In addition, all three steps happen before a directory is recursed into (so this is not equivalent to e.g.
chmod -R a=r /foo
chmod -R u+w /foo
chmod -R a+X /foo
since the a=r removes x from directories, so then chmod can't recurse into them.)
On https://help.directadmin.com/item.php?id=589 they write:
If you need a quick way to reset your public_html data to 755 for directories and 644 for files, then you can use something like this:
cd /home/user/domains/domain.com/public_html
find . -type d -exec chmod 0755 {} \;
find . -type f -exec chmod 0644 {} \;
I tested and ... it works!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With