5 March 2014

Give permissions recursively to files or directories in Linux terminal. Often I find that people give wrong permissions for files and directories in their web projects. It is unsafe to give all files execution rights in Linux. Especially I find that Windows users have execution permissions for files by default and then upload them to server. Web projects PHP files shouldn't have execution rights at all. This example gives 644 for files and 755 for directories. You can use these commands for any kinds of permission changes. NB: Pay attention to users and groups.

Source code viewer
  1. # Give 644 for all files in directory YOUR_DIR relative to current directory.
  2. find YOUR_DIR/ -type f -print0 | xargs -0 chmod 644
  3.  
  4. # Give 755 for all directories in directory YOUR_DIR relative to current directory.
  5. find YOUR_DIR/ -type d -print0 | xargs -0 chmod 755
Programming Language: Bash