[LINUX] Recursively change permissions only on files or dirs

Use the command below to recursively change permissions only on files:

~$ find /<path> -type f -exec chmod 644 {} \;

While use the following command to recursively change permissions only on directories:

~$ find /<path> -type d -exec chmod 755 {} \;

where:
/<path> is the path containing the interested files or directories.
644 assigns permissions of “read/write” on the owner, while “read” on the group and others.
755 assigns permissions of “read/write/execute” on the owner, while “read/execute” on the group and others.

[LINUX] Recursively change permissions on specific file type

Use the following command to recursively change permissions only on specific file type (e.g, all php files in the main path and related sub-directories):

~$ find . -name "*.php" -exec chmod +x {} \;

The command above searches all php files and excute the chmod command to apply the execution permission (+x).

If you have found this post useful, please visit the Contribute page