How to change file and folder permissions using command line

Sometimes we require to change files and folders permissions. Command line or SSH terminal is best option to change mass permission change in files or folders. In this article we learn how to change files and folder permission using command line.

chmod command is used for file or folder permission change.

For example.

chmod 644 test.php

This above command change test.php file permission to 644 (rw-r–r–). If there is space in file name then put quotation mark around file name.

You can also change multiple files permission using single command as below,

chmod 644 test.php test.txt demo.html

For multiple file permission change write list of files using space as above, and it will change permission to all files. Note that all files will be store in current directory.

Same way you can change folder permission with same command.

chmod  755 folder1

Above command will change permission to folder1. But if you want to change permission recursively then you need to add -R in command as below.

chmod -R 755 folder1

This above command will change folder1 permission as well as it will also change all sub folders and files permission which exists in folder1.

chmod command is also useful with other commands. For example, if you want to change permission to files only not any folder permission, then use below command.

chmod command to change permission to files only.

find . -type f -exec chmod 644 {} \;

chmod command to change permission to all folders only.

find . -type d -exec chmod 755 {} \;