How to Change Permissions of All Files in a Folder in Linux?

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

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.file permission

  1. Read permission (r): Allows a user to view the contents of a file or lists of a directory, but cannot modify them.
  2. 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.
  3. 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

General process to change permissions of all files in a folder in linux

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.

You can read our Comparative Analysis of Methods to distinguish between these two methods and best pick one for your needs.

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 >

  1. At first, go to your desired directory.change directory in Linux
  2. Then select all the files in the folder and right-click to view the properties.select all files to view properties in Linux
  3. After that, select the properties to view the permissions of all the files.select properties of files in linux
  4. Now, go to the permissions and select read and write permission.give read and write permissions to the files in Ubuntu
  5. Uncheck the checkbox to remove the execute permission of all the files in the directory.execute the permissions for files in Linux

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 >

  1. To initiate, press CTRL+ALT+T to open the Ubuntu Terminal.
  2. Then, copy the command below to see your present working directory and press the ENTER button.
    pwd
    EXPLANATION
    • pwd: Shows the present working directory.
  3. After that, execute the following command.
    cd /home/sylvie/Summer
    EXPLANATION
    • cd: Used to change directory.
    • /home/sylvie/Summer: Path of the directory.
    Change the directory in UbunutAs you can see, the directory is changed from home to Summer.
  4. To view the current permissions of all the files in the Summer folder run the command below and hit the ENTER button.
    ls -l
    EXPLANATION
    • ls: Shows all the files in a specific folder.
    • option -l: Long listing format.
    View Permission of All Files in a FolderIn the image above, you can view the permission for all the files in the Summer folder.
  5. 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.
     change permission of all files in folder
  6. Finally, run the command below to check if the permissions of all the files in the Summer folder are changed.
    ls -l
    EXPLANATION
    • ls: Shows all the files in a specific folder.
    • option -l: Long listing format.
     Verify permission of all files in folderAs you can see in the above image, the permission of all the files in the folder is changed using the chmod command.

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 >

  1. At first, open the Ubuntu Terminal.
  2. Then, copy the command below to see your present working directory and press the ENTER button.
    pwd
    EXPLANATION
    • pwd: Shows the present working directory.
  3. After that, type the following command and tap the ENTER button to navigate to the desired folder.
    cd /home/sylvie/Summer
    EXPLANATION
    • cd: Used to change directory.
    • /home/sylvie/Summer: Path of the directory.
     Change the directoryAs you can see, the directory is changed from home to Summer.
  4. To view the current permissions of all the files in the Summer folder run the command below and hit the ENTER button.
    ls -l
    EXPLANATION
    • ls: Shows all the files in a specific folder.
    • option -l: Long listing format.
    View Permission of All Files in a Folder in LinuxIn the image above, you can view the permission for all the files in the Summer folder.
  5. 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.
    change permission of all files in a folder in Linux
  6. Finally, run the command below to check if the permissions of all the files in the Summer folder are changed.
    ls -l
    EXPLANATION
    • ls: Shows all the files in a specific folder.
    • option -l: Long listing format.
    Verify permission of all files in a folder in LinuxAs 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.


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 >

  1. At first, open the Ubuntu Terminal.
  2. Then, copy the command below to see your present working directory and press the ENTER button.
    pwd
    EXPLANATION
    • pwd: Shows the present working directory.
  3. After that, type the following command and tap the ENTER button to navigate to the desired folder.
    cd /home/sylvie/Summer
    EXPLANATION
    • cd: Used to change directory.
    • /home/sylvie/Summer: Path of the directory.
    Change the directoryAs you can see, the directory is changed from home to Summer.
  4. To view the current permissions of all the files in the Summer folder run the command below and hit the ENTER button.
    ls -l
    EXPLANATION
    • ls: Shows all the files in a specific folder.
    • option -l: Long listing format.
     View Permission of All Files in a FolderIn the image above, you can view the permission for all the files in the Summer folder.
  5. 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.
     change permission of all files in folder
  6. Finally, run the command below to check if the permissions of all the files in the Summer folder are changed.
    ls -l
    EXPLANATION
    • ls: Shows all the files in a specific folder.
    • option -l: Long listing format.
    Verify permission of all files in folder in LinuxAs 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.

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
  • Easy to use & user-friendly.
  • Users do not require prior knowledge or experience.
  • Users can see the results of their actions immediately, which can be helpful for troubleshooting.
  • Users are already familiar with the use of GUI.
  • Limited user control.
  • Not easily scriptable.
  • Different operating systems may have different GUIs, which can lead to inconsistency and confusion.
  • Some users may unintentionally change the permissions of files or folders to which they should not have access.

 

Change permission using CLI
  • Offers more control to modify permission.
  • Can be used in scripts and automated processes.
  • Users can see the results of their actions immediately.
  • Supports both symbolic and octal notation, which gives the ability to specify permission changes with flexibility.
  • Has to be familiar with terminal commands.
  • Can be harmful if used inappropriately.
  • Does not offer much feedback beyond success or failure, which might make troubleshooting errors more difficult.
  • The syntax can be complex and difficult to understand.

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 >

  1. Start by pressing CTRL+ALT+T to open the Ubuntu Terminal.
  2. Now, view the current permissions of the Summer folder, run the following command in the command prompt:
    ls -l
    EXPLANATION
    • ls: Shows all the files in a specific folder.
    • option -l: Long listing format.
    View Permission of FolderAs you can see, the output shows the folder permissions.
  3. 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.
    change file permissions of a folder in Linux
  4. Finally, run the command below to check if the permissions of the Summer folder are changed.
    ls -l
    EXPLANATION
    • ls: Shows all the files in a specific folder.
    • option -l: Long listing format.
    Verify permission of a folder in LinuxAs you can see in the above image, the permission of the folder is changed using the chmod command.


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 >

  1. Open the Terminal in Ubuntu.

  2. 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
    EXPLANATION
    • ls: Shows all the files in a specific folder.
    • option -l: Long listing format.
    • Summer: The folder to change permission.
    view directory's permissionIn the image above, you can view the current permission of the Summer directory.view subfolder permission in LinuxIn the snapshot above, you can view the current permission of the subdirectory Fruits of the Summer directory.

  3. 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.
    change file permissions of a folder in Linux
  4. Finally, run the following commands to check if the permissions of the Summer directory and Fruits subdirectory are changed:
    ls -l
    ls -l Summer
    EXPLANATION
    • ls: Shows all the files in a specific folder.
    • option -l: Long listing format.
    • Summer: The folder to change permission.
     verify folder and subfolder permissionAs you can see in the image above, the permission of both the directory and subdirectory changed at the same time with a single command.

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

What are the 3 types of permissions?
In Linux, there are three different permission types: read, write, and execute. These permissions determine what operations can be performed on a file or directory.
What do the letters in the chmod command mean?
The letters in the chmod command stand for the various operations and permission levels. The initial three letters, “u,” “g,” and “o,” stand for the owner, the group, and the others, respectively. The second letter ‘r’, ‘w’, and ‘x’ indicate read, write, and execute permissions. The third letter ‘+’ and ‘-‘ are used to add and delete permissions.
How do I give read/write access to a specific user on a file?
To give a specific user read/write access to a file, use the “chown” command to change the file’s ownership to that user, then use the “chmod” command to give that user read and write permissions.
How do I change the owner of a file in Linux?
To change the owner of a file in Linux, use the “chown” command, followed by the new owner’s username and the file name. For instance, “sudo chown newOwner fileOne” would make “newOwner” the owner of “fileOne”.
How do I view the current permissions of a file in Linux?
In Linux, use the “ls” command, followed by the “-l” option and the file name, to view the current permissions of a file. This will show a detailed list of the file’s information, including the owner, group, and others and their respective permissions.
How do I add execute permission to a file in Linux?
In Linux, use the “chmod” command, followed by the permission level and the file name, to add execute permission to a file. For instance, “sudo chmod +x fileOne” would give the file “fileOne” execute permission.
How do I set default permissions for newly created files in a directory?
You can use the “umask” command followed by the desired permissions to specify default permissions for newly created files in a directory. For instance, “umask 002” would change the default permissions to allow read, write, and execute permissions for the owner and group, and read and execute permissions for others.

Related Articles

Rate this post
LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now
icon linux
Jannatul Ferdousi Sylvie

Hi there! This is Jannatul Ferdousi Sylvie. I am one of the Linux Content Developer Executives at Softeko. I live in Dhaka, Bangladesh. I have completed my BSc. in Software Engineering from American International University-Bangladesh. You can see my projects in the GitHub account. I love traveling, shopping, cooking, and gardening. Read Full Bio

Leave a Comment