Change permissions using find command

To change permissions using find command.

On a Linux server, if you are in need of changing the permissions of a bulk amount of files or directories recursively, we can use the ‘find’ command to do it. The steps are explained below:

Change to the directory in which you need to change the permissions.

cd /home/user/public_html 

Changing Files

The permission changes are different based on the situation we are having. If you need to change the permissions of all files inside the directory to 644 recursively, please use the following:

find . -type f -exec chmod 644 {} \;

You can specify a specific directory in the following way as well:

find /home/abc/ -type f -exec chmod 644 {} \;

Directories

If you are looking to change the permissions of directories inside the current folder to 755, use the following:

find /home/abc/ -type d -exec chmod 755 {} \;

If you are looking to change the permissions of all files having 777 permissions only to 644, use the following:

find . -type f -perm 777 -exec chmod 644 {} \;

Use the same format for directories by changing the option f:

find . -type d-perm 777 -exec chmod 755 {} \;

You can also change permission using xargs command to do this quickly.

find . -type d -print0 | xargs -0 chmod 755
find . -type f -print0 | xargs -0 chmod 644

Leave a Comment