I want to set 755 permission on all files and sub-directories under a specific directory, but I want to execute chmod 755 only for those components which does not have 755 permission.
find /main_directory/ -exec chmod 755 {} \;
If the find
command returns a long list, this will take a lot of time.
I know that I can use the stat command to check the Octal file level permission of each component and then use if-else to toggle the file permission, but is there any single line approach using find
and xargs
to first check what permission the file/directory has, and then use chmod
to change it to 755 if it is set to something else.
u+rw,go+r,go-w,ugo+X
— note the capital.