In Linux, permissions restrict access to files and directories. There are three categories of users for whom permissions can be set: the file’s owner, the members of the group that owns the file, and all others. Changing the permissions for all files in a folder can be helpful in various circumstances, such as when you want to grant a group of users read, write, and execute permission or limit access to specific files. In this article, I will demonstrate how to change the permissions of all files in a folder in Linux.
Key Takeaways
- Learning about read, write & execute permission in Linux.
- Different methods of modifying permission using GUI & CLI.
- Knowing about frequently asked questions and their answers regarding file permission.
Requirements
- You must be a root user or have root/sudo access to Ubuntu.
- You need to determine the desired permission for all the files.
Read, Write & Execute Permissions in Linux
File and directory permissions are used in Linux to control resource access. Read, write, and execute permissions, which are denoted by the letters “r,” “w,” and “x,” respectively, are three basic forms of permissions. These permissions can be assigned to 3 types of users: the file or directory’s owner, the group that owns the file or directory, and others.
- Read permission (r): Allows a user to view the contents of a file or lists of a directory, but cannot modify them.
- Write permission (w): Allows a user to modify the contents of a file or to create, delete, or rename files in a directory. For example, a user with only written permission on a file can modify its contents but can’t view or execute it.
- Execute permission (x): Allows a user to run an executable file or change into a directory, but can not view or write onto it.
Read, write, and execute permissions can be represented using either octal or binary numbers. The table below shows octal representation, binary representation, file permission set, and corresponding permissions of any file/directory.
Octal Representation | Binary Representation | File Permission Set |
Permission |
||
---|---|---|---|---|---|
0 | 000 | — | No permission | ||
1 | 001 | –x | Execute | ||
2 | 010 | -w- | Write | ||
3 | 011 | -wx | Write | Execute | |
4 | 100 | r– | Read | ||
5 | 101 | r-x | Read | Execute | |
6 | 110 | rw- | Read | Write | |
7 | 111 | rwx | Read | Write | Execute |
Process Flow Chart
Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTS
Watch 4 Methods to Change Permissions of All Files in a Folder in Linux
4 Methods to Change Permissions of All Files in a Folder in Linux
Here, I’ve shown you four methods to change the permissions of all files in a folder which include one method using GUI & three methods using CLI in Linux.
Method 1: Change Permissions of All Files Using GUI
I have demonstrated how to change the permissions of all files in a folder using GUI for beginners. Just follow all the steps below to change permissions using GUI in Linux.
Steps to Follow >
- At first, go to your desired directory.
- Then select all the files in the folder and right-click to view the properties.
- After that, select the properties to view the permissions of all the files.
- Now, go to the permissions and select read and write permission.
- Uncheck the checkbox to remove the execute permission of all the files in the directory.
Method 2: Using the chmod Command to Change Permissions in Linux
Here, you will learn how to change the permissions of all files in a folder using the chmod command in Linux. Follow the instructions below for a better understanding.
Steps to Follow >
- To initiate, press CTRL+ALT+T to open the Ubuntu Terminal.
- Then, copy the command below to see your present working directory and press the ENTER button.
pwd
EXPLANATION- pwd: Shows the present working directory.
- After that, execute the following command.
cd /home/sylvie/Summer
As you can see, the directory is changed from home to Summer.EXPLANATION- cd: Used to change directory.
- /home/sylvie/Summer: Path of the directory.
- To view the current permissions of all the files in the Summer folder run the command below and hit the ENTER button.
ls -l
In the image above, you can view the permission for all the files in the Summer folder.EXPLANATION- ls: Shows all the files in a specific folder.
- option -l: Long listing format.
- Now, execute the following command to change the permissions for all the files in the Summer folder.
chmod 764 *
EXPLANATION- chmod: Changes file permissions.
- 764: Read, Write & Execute permission.
- *: Indicates all files in the folder.
- Finally, run the command below to check if the permissions of all the files in the Summer folder are changed.
ls -l
As you can see in the above image, the permission of all the files in the folder is changed using the chmod command.EXPLANATION- ls: Shows all the files in a specific folder.
- option -l: Long listing format.
Method 3: Change Permissions With the find & chmod Commands
In this method, you will learn to change the permissions of all files in a folder using the chmod command along with the find command in Linux. Follow the following procedure for better understanding.
Steps to Follow >
- At first, open the Ubuntu Terminal.
- Then, copy the command below to see your present working directory and press the ENTER button.
pwd
EXPLANATION- pwd: Shows the present working directory.
- After that, type the following command and tap the ENTER button to navigate to the desired folder.
cd /home/sylvie/Summer
As you can see, the directory is changed from home to Summer.EXPLANATION- cd: Used to change directory.
- /home/sylvie/Summer: Path of the directory.
- To view the current permissions of all the files in the Summer folder run the command below and hit the ENTER button.
ls -l
In the image above, you can view the permission for all the files in the Summer folder.EXPLANATION- ls: Shows all the files in a specific folder.
- option -l: Long listing format.
- Now, execute the following command to change the permissions for all the files in the Summer folder.
find . -type f -exec chmod 467 {} ;
EXPLANATION- find: Used to perform search operations.
- (.): Means the current folder.
- –type f: Specifies only regular files.
- -exec: Used to execute the chmod command on each file found by the find command.
- chmod: Changes file permissions.
- 467: Read, Write & Execute permission.
- {}: Placeholder for the current pathname.
- : Used before (;) to treat it like an argument rather than a separator.
- ;: Indicates the end of the command.
- Finally, run the command below to check if the permissions of all the files in the Summer folder are changed.
ls -l
As you can see in the above image, the permission of all the files in the folder is changed using the find command and the chmod command.EXPLANATION- ls: Shows all the files in a specific folder.
- option -l: Long listing format.
- How to Give Permission to User in Linux? [4 Methods]
- 2 Ways to Change Folder Permissions from Root to User in Linux
Method 4: Change Permissions in Linux Using the xargs & chmod Commands
You will get to know how to change all the files’ permissions using the chmod command along with the xargs command in Linux. For a better understanding, follow the process below.
Steps to Follow >
- At first, open the Ubuntu Terminal.
- Then, copy the command below to see your present working directory and press the ENTER button.
pwd
EXPLANATION- pwd: Shows the present working directory.
- After that, type the following command and tap the ENTER button to navigate to the desired folder.
cd /home/sylvie/Summer
As you can see, the directory is changed from home to Summer.EXPLANATION- cd: Used to change directory.
- /home/sylvie/Summer: Path of the directory.
- To view the current permissions of all the files in the Summer folder run the command below and hit the ENTER button.
ls -l
In the image above, you can view the permission for all the files in the Summer folder.EXPLANATION- ls: Shows all the files in a specific folder.
- option -l: Long listing format.
- Now, execute the following command to change the permissions for all the files in the Summer folder.
ls | xargs chmod 750
EXPLANATION- ls: Used to perform search operations.
- xargs: Used to pass one command’s output to another command’s input.
- chmod: Changes file permissions.
- 750: Read, Write & Execute permission.
- Finally, run the command below to check if the permissions of all the files in the Summer folder are changed.
ls -l
As you can see in the image above, the permissions of all the files in the folder are changed using the exec command along with the chmod command.EXPLANATION- ls: Shows all the files in a specific folder.
- option -l: Long listing format.
Comparative Analysis of Methods
Since this article offers multiple approaches for a single task, you may be confused about which one to choose. For your convenience, I have provided a comparison of the two different ways that use GUI and CLI in this section.
Methods | Pros | Cons |
---|---|---|
Change permission using GUI |
|
|
Change permission using CLI |
|
|
Thus, it can be considered that both approaches have perks and drawbacks of their own. The right approach differs from user to user. If you are a beginner, I would suggest you use the GUI to change the permission but for an advanced user, the use of CLI would be best in my opinion.
Complementary Information
You will find the following information helpful along with learning how to change the permissions of all the files in a specific folder in Linux.
Change Folder Permissions in Linux to 755
You can change folder permissions to 755 in Linux. Follow the instructions below for a better understanding.
Steps to Follow >
- Start by pressing CTRL+ALT+T to open the Ubuntu Terminal.
- Now, view the current permissions of the Summer folder, run the following command in the command prompt:
ls -l
As you can see, the output shows the folder permissions.EXPLANATION- ls: Shows all the files in a specific folder.
- option -l: Long listing format.
- Then, change the permission to 755, execute the following command in the command prompt:
chmod 755 Summer
EXPLANATION- chmod: Changes file permissions.
- 755: Read, Write & Execute Permission.
- Summer: The folder to change permission.
- Finally, run the command below to check if the permissions of the Summer folder are changed.
ls -l
As you can see in the above image, the permission of the folder is changed using the chmod command.EXPLANATION- ls: Shows all the files in a specific folder.
- option -l: Long listing format.
- How to Change File Permissions to 777 in Ubuntu?
- 2 Ways to Change Folder Permissions Recursively in Linux
Change Permission of Directory and Subdirectory Using the chmod Command Recursively
You can change a directory and subdirectory’s permission at once using the chmod command in recursive mode. For this, you need to add the -R option to the chmod command. You can do this by following the procedure below.
Steps to Follow >
- Open the Terminal in Ubuntu.
- To view the current permissions of the Summer directory and its subdirectory Fruits, run the following commands in the command prompt:
ls -l
ls -l Summer
In the image above, you can view the current permission of the Summer directory.In the snapshot above, you can view the current permission of the subdirectory Fruits of the Summer directory.EXPLANATION- ls: Shows all the files in a specific folder.
- option -l: Long listing format.
- Summer: The folder to change permission.
- Now, change the permission of the directory and subdirectory concurrently, execute the following command in the command prompt:
chmod -R 764 Summer
EXPLANATION- chmod: Changes file permissions.
- -R option: Enables recursive mode.
- 764: Read, Write & Execute Permission.
- Summer: The folder to change permission.
- Finally, run the following commands to check if the permissions of the Summer directory and Fruits subdirectory are changed:
ls -l
ls -l Summer
As you can see in the image above, the permission of both the directory and subdirectory changed at the same time with a single command.EXPLANATION- ls: Shows all the files in a specific folder.
- option -l: Long listing format.
- Summer: The folder to change permission.
Conclusion
In Linux system administration, changing the permissions of all the files in a folder is a common task. In this tutorial, I’ve discussed the four most commonly used methods for modifying the permissions of all files in a folder in Linux. Choose the method that suits you best. While changing permissions, keep in mind to proceed with caution to avoid unwanted consequences.
People Also Ask
Related Articles
- Manage File Permissions in Ubuntu Using Command?
- How to Change File Permissions in Linux? [6 Examples]
- 2 Cases to Give User Permission to Folder and Subfolders in Ubuntu
- How to Change Directories and Files Recursively with “chmod”
- Change Permissions on Mounted Drive in Linux
- How to Change Folder Permissions in Linux? [2 Methods]
FUNDAMENTALS A Complete Guide for Beginners