How to recursively change permissions on all directories inside current directory?
Solution 1
You're missing a space after 644.
Also, 644 is probably not what you want on a directory. You probably want 755.
Edit to include answer from comments below:
For directories:
find . -type d -exec chmod 755 {} \;
For files:
find . -type f -exec chmod 644 {} \;
There's very likely other ways (maybe shorter) to do this, but this will work.
Solution 2
Another way to do this is:
chmod -R u=rwX,g=rX,o=rX /path/to/dir
The capital X is a conditional execute- if the file is a directory the execute bit gets added OR if the file is already executable the execute bit gets retained.
Though this would add permissions to non directory files. If these permissions are acceptable, this works for quickly adding access to folders.
Related videos on Youtube
Alan Kis
Updated on September 18, 2022Comments
-
Alan Kis over 1 year
How can I change folder and file permissions for all files and folders recursively inside current directory? I am not sure, why, but my command fails with this
output: chmod: missing operand after '644./components/path/path/path'
My command is:
find . * -type d -exec chmod 755{} \;
As user pdo pointed, I want change folder permissions to 755-
-
Alan Kis over 8 yearsYes, I want to 755. Now I got find: '.', '*' .Permission denied, and failed to restore initial working directory.
-
Geoff over 8 yearsWhat are the permissions on the current working directory?
-
Paul Calabro over 8 yearsPrefix the command with sudo and it should work if you have permission to do so.
-
roaima over 8 yearsYou mgiht want to add this (or something like it) to your answer to make your suggestion explicit:
find . -type d -exec chmod 755 {} +
-
Alan Kis over 8 years@pdo, current working directory is 750. I am not root, this is jailed cPanel shell.
-
Geoff over 8 years@AlanKis let's restate the problem: you want to change the permissions on all directories under the current working directory to 755?
-
Alan Kis over 8 years@pdo, exactly, and files to 644.
-
Geoff over 8 years@AlanKis ok, so:
find . -type d -exec chmod 755 {} \;
for the directories, andfind . -type f -exec chmod 644 {} \;
-
Alberto Salvia Novella almost 3 yearsThis works 👍👍