SSH commands allows user to manage files and directories easily. We have shared multiple articles on related topics. Today, we’re going to discuss in-detail procedure to change file permissions recursively in Linux.
#1. Change File Permissions Recursively from SSH Terminal
We will execute multiple commands to change file permission via SSH terminal. So login to SSH with the required credentials. You may check the video tutorial to login to SSH.
Before proceeding to change file permission, I will suggest you to check the current file permission of the files inside the path or directory for which you want to change the permission. Execute ls -l command and list of all the files with their permission will appear. Now, let us go through the commands to change files permission recursively.
To change the permission of single file we use chmod command as:
chmod 0666 /home/new/abc
In the above command,
0666 is the file permission
/home/new/abc is the path of the file of which I want to change the permission. You can change them as per your requirement.
We will now change file permission of multiple files in a current directory or files inside a directory.
How to Change Multiple File Permissions?
Use the above command with multiple file names as:
chmod 0744 /home/new/abc /home/new/test
How to Change File Permission Recursively in a directory?
Execute the below given command to do the same.
chmod -R 0740 path/of/the/directory
To verify the changes use the ls -l command to list files with their file permissions.
Now, to execute the above command for changing file permission recursively, directory should have executable permission. So, you can use the following command to change file permission recursively in a directory not having executable permission.
chmod -R u=rwX,go=rX /path/of/the/directory
How to Change File Permission of the files from one to another?
In this we can change the file permission of the files inside a particular sub-directory or with a particular file permission.
First we will check the files with file permission 0755. Execute the below command to print all the files with 0755 permission.
find /path/of/the/directory -type f -perm 0755 -print
Change the files with file permission 0755 to 0644. Execute the below given command to change the file permission of set of files.
Now, suppose you want to change the file permission of all the files in a directory or sub-directory, then you can simply do that from cPanel without running the PHP file. But what if you want to change the file permission of all the files named test.php from 0644 to 0755 or any other.
So, instead of finding a file with the same name in whole cPanel, you can simply run the shell command using PHP file to change file permission. Let us see the whole procedure to do the same.
Login to your cPanel account and get inside File Manager section.
Now, hit the file from the browser. You will receive a blank page. Get back to cPanel and reload the page to verify the changes.
That’s It !
Hope the article better describes the procedure to change file permissions recursively. Do share it with your colleagues if you find it working. Also share your suggestions and drop your queries to start the discussion on the related topic. Lets connect on social media with the below links.