Before you start
Changing for everything
Using the -R parameter of chmod command it is possible to recursively apply the same permission to all files and folders.
$ Shell
chmod -R 755 /path/to/base/dir
For files or folders separately, see below.
Directories
To change permission of all subdirectories recursively from a base directory.
$ Shell
# Permission 755 (drwxr-xr-x) find /path/to/base/dir -type d -exec chmod 755 {} + # Other way chmod 755 $(find /path/to/base/dir -type d) # For directories with too many files find /path/to/base/dir -type d -print0 | xargs -0 chmod 755 # Uses the current folder as base directory find . -type d -exec chmod 755 {} +
Permissions 755 (drwxr-xr-x) were used, which is more common for directories and is the default option when creating new folders.
The dot (.) represents the current directory and can be used in place of the path to the base directory in any of the above commands.
Files
To change the permissions of all files in the base directory defined in the command and its subdirectories recursively:
$ Shell
# Permission 644 (-rw-r--r--) find /path/to/base/dir -type f -exec chmod 644 {} + # Other way chmod 644 $(find /path/to/base/dir -type f) # For directories with many files find /path/to/base/dir -type f -print0 | xargs -0 chmod 644 # Uses the current folder as base directory find . -type f -exec chmod 644 {} +
Permissions 644 (-rw-r--r--) were applied, which is the default used when creating text files. Using this permission on a script will remove its execution permission which will make it lose its functionality.