How to change all file permissions to 644 and all folder permissions to 755 recursively using chmod in the following two situation:
- If they had
777
permissions - Regardless of the permission (with ANY permissions)
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.
Sign up to join this communityHow to change all file permissions to 644 and all folder permissions to 755 recursively using chmod in the following two situation:
777
permissionsfind . -type d -perm 777 -exec chmod 755 {} \;
(for changing the directory permission)
find . -type f -perm 777 -exec chmod 644 {} \;
(for changing the file permission)
If the files/directories dont have 777
permissions, we easily remove the -perm 777
part. The advantage of these commands is that they can target regular files or directories and only apply the chmod to the entries matching a specific permission.
.
is the directory to start searching
-type d
is to match directories (-type f
to match regular files)
-perm 777
to match files with 777 permissions (allowed for read, write and exec for user, group and everyone)
-exec chmod 755 {} \;
for each matching file execute the command chmod 755 {}
where {} will be replaced by the path of the file. The ;
indicates the end of the command, parameters after this ;
are treated as find
parameters. We have to escape it with \
since ;
is the default shell delimiter, it would mean the end of the find
command otherwise.
Regardless of the permissions:
chmod -R a=r,a+X,u+w /your/path
chmod -R "$(umask -S | sed 's/x/X/g')" /your/path
Jan 30, 2020 at 22:50
all=set to readonly,all=add execute if folder,owner=add write
... And it is INFINITELY better than all the stupid find
answers. Find has to launch a chmod process for every file/folder. @adaptr 's answer only does a single, efficient chmod process.
Jan 28 at 16:04
sudo find /path/to/someDirectory -type f -print0 | xargs -0 sudo chmod 644
and
sudo find /path/to/someDirectory -type d -print0 | xargs -0 sudo chmod 755
chmod
itself.
Jan 28 at 16:53