Use chmod command selectively
If you want to change permissions to 755
on both files and directories, there's no real benefit to using find
(from a performance point of view at least), and you could just do
chmod -R 755 /main_directory
If you really want to use find
to avoid changing permissions on things that already has 755
permissions (to avoid updating their ctime timestamp), then you should also test for the current permissions on each directory and file:
find /main_directory ! -perm 0755 -exec chmod 755 {} +
The -exec ... {} +
will collect as many pathnames as possible that passes the ! -perm 0755
test, and execute chmod
on all of them at once.
Usually, one would want to change permissions on files and directories separately, so that not all files are executable:
find /main_directory -type d ! -perm 0755 -exec chmod 755 {} +
find /main_directory ! -type d ! -perm 0644 -exec chmod 644 {} +