Linux - How to recursively chmod a folder?
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Future Grid Looping
--
Chapters
00:00 Linux - How To Recursively Chmod A Folder?
00:26 Accepted Answer Score 326
01:38 Answer 2 Score 45
02:07 Answer 3 Score 7
02:24 Answer 4 Score 1
02:41 Answer 5 Score 0
02:50 Thank you
--
Full question
https://superuser.com/questions/1325221/...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#chmod
#avk47
ACCEPTED ANSWER
Score 326
Please refer to the manual (man chmod
):
-R, --recursive
change files and directories recursively
chmod -R 755 /path/to/directory
would perform what you want.
However…
You don't usually want to 755 all files; these should be 644, as they often do not need to be executable. Hence, you could do
find /path/to/directory -type d -exec chmod 755 {} \;
to only change directory permissions. Use-type f
andchmod 644
to apply the permissions to files.This will overwrite any existing permissions. It's not a good idea to do it for
/var
— that folder has the correct permissions set up by the system already. For example, some directories in/var
require 775 permissions (e.g.,/var/log
).
So, before doing sudo chmod
— particularly on system folders — pause and think about whether that is really required.
ANSWER 2
Score 45
For a PHP-based web site, many sources like this one recommend 755 for directories and 644 for files.
If you are in the DocumentRoot of the website, you can set this as follows:
find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;
ANSWER 3
Score 7
If you wish to apply chmod
to a specific directory/ file you can make use of find
as following:
find . -type f -name "*.sh" -print0 |xargs -0 chmod 755
ANSWER 4
Score 1
To set the rights for all files (to 644) and all directories (to 755) in your directory YOUR_CATALOG at once you can use this:
find YOUR_CATALOG -type f -exec chmod 664 {} + -o -type d -exec chmod 775 {} +
ANSWER 5
Score 0
You can give all permission for your localhost
sudo chmod -R goa=rwx /path/to/directory