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)
chmoddirectorypermissionsrecursive
How to change all file permissions to 644 and all folder permissions to 755 recursively using chmod in the following two situation:
777
permissions
Best Answer
find . -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 commandchmod 755 {}
where {} will be replaced by the path of the file. The;
indicates the end of the command, parameters after this;
are treated asfind
parameters. We have to escape it with\
since;
is the default shell delimiter, it would mean the end of thefind
command otherwise.