Linux Commands

How to Check Folder Permission Linux

Linux is a multi-user operating system. It can handle multiple users accessing the system at the same time. This is one of the key reasons why Linux is so popular in mainframes, servers, supercomputers, etc. Being a multi-user system, it’s paramount to have functional user permission management. It’s the fundamental that defines what user/group can access what part of the system.

For file access, this user permission is managed as the file permissions. In this guide, we’ll have a deep dive into the file and folder permissions in Linux.

Prerequisites

To understand the file and folder permissions, it’s important to understand several key concepts. In this section, we’ll describe each of them briefly.

Users and User Groups

Linux allows access to the systems to individual users. Any valid user can connect to the system locally or remotely and enjoy access to whatever resource is allocated.

If there are hundreds of users, then managing all their permissions individually is quite inefficient. To solve this, Linux introduces the concept of user groups. Each group may contain one or more users. Changing permissions for the user group will automatically be applied to every user within that group.

Checking File and Folder Permissions

Depending on the type of UI, there are two ways you can check the file permissions of a folder/directory.

Checking File Permission Using GUI

If your distro comes with a desktop environment, then it will also likely have a file manager installed. All the file managers can check and show the file permissions. For demonstration, let’s have a look at Nautilus, the default file manager in GNOME.

Right-click on any file/folder, and select “Properties”.

To check the permissions, head to the “Permission” tab.

Checking File Permission Using CLI

This is the more recommended (albeit slightly confusing) method of checking file permissions in Linux. We’ll be using the ls tool that comes preinstalled in all Linux distros.

To check the file permissions, run the following ls command. Check out this guide for an in-depth exploration of the ls command.

$ ls -l <path_to_file_dir>

If no file location is specified, then ls will print info about all the files in the current directory. Note that ls may not print the file permissions and info if it’s a directory.

For example, when trying to check permissions for the directory “~/Desktop”, ls won’t print any info at all.

$ ls -l ~/Desktop

In such a situation, run ls on the parent directory of the target directory. In this case, it’s “~/”.

$ ls -l ~

Explaining the file permissions

As we can see, the file permission is described as a string of some ASCII characters. This guide on Linux file permissions explains everything in more detail. Here, we’ll have a brief overview.

There are 3 permission types.

  • read (r) – The user’s capability to read the file content.
  • write (w) – The user’s capability to write or modify the file or contents of the directory.
  • execute (x)- The user’s capability to execute the file or see the contents of the directory.

The permission string contains the following data.

  • Character 1: Describes the file type(directory, symlink, setuid/setgid permissions, or sticky bit permissions).
  • Character 2-4: Describes the file permission for the owner.
  • Character 5-7: Describes the group permissions for the file.
  • Character 8-10: Describes the file permission for everyone else in the system.

For the file type, there are a couple of different values.

  • _ : No special permissions.
  • d : Directory
  • l: Symbolic link, also known as symlinks. Learn more about symlinks in Linux.
  • s: setuid/setgid permissions.
  • t: Sticky bit permissions.

Modifying File and Folder Permissions

The file permissions are important values. However, with the right authority, a user in the Linux system can change the file permission.

To change the permissions, Linux comes with a built-in tool called chmod. For example, to mark a script file as an executable, we’d run the following command.

$ chmod +x <script_file>

If you wanted to remove the “executable” flag from the file, then the command would look like this.

$ chmod -x <script_file>

For a beginner, it’s recommended to practice various chmod commands, for example, granting a user permission to a folder. The next guide goes deeper into chmod with explanations.

Changing File Ownership

The owner of a file also impacts the file permissions. Generally, it’s the user that originally created the file. However, different users can be assigned as the owner of the file or directory.

To change the ownership of a file, Linux comes with the tool chown.

Final Thoughts

File permission is an important concept in Linux. Checking file permission for a folder is an easy task. Linux comes with the necessary tools to manage them directly from the command line. This guide successfully demonstrates checking and modifying the file permission of files and folders.

Happy computing!

About the author

Sidratul Muntaha

Student of CSE. I love Linux and playing with tech and gadgets. I use both Ubuntu and Linux Mint.