}

How to set chmod for a directory and all of its subdirectories and files using the Ubuntu terminal?

Created:

Suppose you want to do a chmod 755 to all the contents of the directory /opt/application, you need to execute the following command:

chmod 755 -R /opt/application

WARNING: changing all files to 755 is not recommended!

If you want to apply 755 only to directories recursively, execute:

chmod -R a+rX *

The previous command will set file permission to a+r and directories to a+x, note the capital X.

As an alternative you can use the find command to apply the permission only to directories:

find /opt/application -type d -exec chmod 755 {} \;

If you don't use the -R option, you will only change the permissions to the directory /opt/application.

You can always execute man chmod to learn more about the usage of chmod.