Learn how to change permissions for files and folders

You may want to change permission for multiple files and folders. This can be done with the chmod shell command.
The syntax for the chmod command is:

root@web [/scripts]# chmod --help
Usage: chmod [OPTION]... MODE[,MODE]... FILE...
  or:  chmod [OPTION]... OCTAL-MODE FILE...
  or:  chmod [OPTION]... --reference=RFILE FILE...
Change the mode of each FILE to MODE.
With --reference, change the mode of each FILE to that of RFILE.

  -c, --changes          like verbose but report only when a change is made
  -f, --silent, --quiet  suppress most error messages
  -v, --verbose          output a diagnostic for every file processed
      --no-preserve-root  do not treat '/' specially (the default)
      --preserve-root    fail to operate recursively on '/'
      --reference=RFILE  use RFILE's mode instead of MODE values
  -R, --recursive        change files and directories recursively
      --help     display this help and exit
      --version  output version information and exit

To change permission for all files in /home/username/public_html to 600, use:

find /home/username/public_html -type f -exec chmod 600 {} \;

To change permission for all directories in /home/username/public_html to 755, use:

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

To change permission for all files and directories in /home/username/public_html to 600, use:

chmod 644 /home/username/public_html -R
In the above examples, use the desired value for permissions (like 600, 700 etc)
Share this post: