How to View File Permissions in Linux?

Learn via video courses
Topics Covered

In this article, we will explore different methods to view file permission in Linux. We will also learn how to change file permissions in Linux and enquire about file ownership. The article will also cover how to check the permissions of a file in Linux.

File permissions in Linux control who can access a file and what they can do with it.

Look at the following table showcasing the types of file permissions in Linux file systems:

SymbolPermissionDescription
rReadThe file can be read.
wWriteThe file can be modified.
xExecuteThe file can be executed or accessed as a directory.
-No accessNo permission to perform the specified action.

By default, new files are created with read and write permissions for the owner and group, and no permissions for others.

The permissions are applied to three categories of users:

CategoryRepresentation
Owneru
Groupg
Otherso

The permission string typically consists of nine characters, where the first three characters represent the permissions for the owner. The next three characters represent the permissions for the group, and the remaining three represent the permissions for others.

UGO_Permissions

Let's start by exploring the methods available for viewing file permissions in Linux.

Using ls Command

Now, we will learn how to check the permissions of a file in Linux using the ls command. The most common and straightforward way to view file permission in Linux is by using this command.

The ls command is a command-line tool to list files and directories. To view the permissions for a file, use the ls command with the -l option.

, For example,, to view the permissions for the file myfile.txt, you would use the following command:

The output will display detailed information about the file, including its permissions, as seen in the image below.
LS_L

In the given output

the breakdown of file permissions is as follows:

The first character - indicates that it is a regular file. The following nine characters rw-rw-r-- represent the file permissions. The owner (sanskriti) has read and write (rw-) permissions, the group (sanskriti) also has read and write (rw-) permissions, and others have only read (r--) permission.

Using GUI

In addition to using the command line, Linux provides a graphical user interface (GUI) method to view file permissions.

Look at the steps involved in viewing file permissions in Linux using the GUI:

  1. Open the file manager. Viewing file permissions in Linux using the GUI

  2. Navigate to the file you want to view the permissions for. Viewing file permissions in Linux using the GUI

  3. Right-click on the file and select Properties. Viewing file permissions in Linux using the GUI

  4. In the Properties window, click on the Permissions tab. Viewing file permissions in Linux using the GUI

  5. The Permissions tab will show the file permissions, the file owner, and the group.

    As you can see in the image below, the user sanskriti and the group named sanskriti have read and write permissions. The others have only read access to the file. Viewing file permissions in Linux using the GUI

Now that you know how to check permissions of a file in Linux, you can effectively manage file access and ensure the security of your system.

In the following section, we will explore how to change the permission of a file in Linux, empowering you to tailor access rights according to your specific requirements.

Q. How to Change the Permission of a File in Linux?

A. Have you ever wondered, "How to change the permission of a file in Linux?" Let's find out!

Linux offers two primary methods to change file permissions: the symbolic method and the octal/numeric method.

Before exploring each method in detail, we will learn about the chmod command.

chmod Command

The chmod command modifies the access permissions for the user (owner), group, and others, granting or revoking the ability to read, write, or execute a file. chmod stands for "change mode."

The syntax for the chmod command is as follows:

The mode can be either a symbolic mode or an octal mode. filename specifies the file or files for which you want to change the permissions. Use the --help flag to see more options for the command.

Now, let's explore how to change the permission of a file in Linux using the symbolic method.

Symbolic Method

The symbolic method allows you to modify file permissions using symbolic representations.

Here is a table summarizing the permissions and symbols used to specify them in Linux:

Permission SymbolDescription
uRepresents the user/owner of the file.
gRepresents the group associated with the file.
oRepresents others (users not in the group).
aRepresents all categories (user, group, and others) combined.
+Adds a permission to the existing permissions.
-Removes permission from the existing permissions.
=Sets the permission explicitly, overriding the existing permissions.
rRepresents read permission.
wRepresents write permission.
xRepresents execute permission.

Steps:

To change the Linux file permissions using the symbolic method, follow these steps:

  1. Open a terminal window and locate the file you want to change permissions for.

  2. Use the chmod command to change the permissions.

  3. , For example,, you can use chmod as follows: chmod u+x myfile.txt adds the execute permission for the file owner. chmod Command

  4. To verify the modification, you can use the ls -l command to view the updated permissions of the file. chmod_ls_l

Now, let's move on to the octal/numeric method to learn how to change the permission of a file in Linux.

Octal/Numeric Method

The Octal mode uses a number to represent the different permissions. Each digit in the number represents a different set of permissions.

Each permission is assigned a number:

Permission ValuePermission Description
0No permission
1Allows the execution of a file or the traversal of a directory.
2Allows modifying or deleting a file, as well as creating or removing files within a directory.
4Allows viewing the contents of a file or listing the files within a directory.

Combinations of Values:
By assigning a single value to permission, you grant that specific permission. You can grant multiple permissions simultaneously by combining values.

To calculate the overall value for permission settings, you add the values of the desired permissions.

For example, a permission setting of 5 grants read(4) and execute(1) permissions.

The general syntax for the octal/numeric method is:

The octal_number represents the numeric value that represents the desired permissions. And, the filename is the file for which you want to change the permissions.

Steps:

To change the file permissions in Linux using the numeric method, follow these steps:

  1. Start by locating the file for which you want to change the permissions.
  2. Open a terminal and use the chmod command to modify the permissions.
  3. Assign the appropriate octal number to represent the desired permissions. , For example,, for the file named myfile.txt, to set read and write permissions for the owner, read-only permissions for the group, and no permissions for others, you would use the octal number 640. Run the below command in the terminal:

Numeric_chmod 5. Check if the permissions are set or not by executing the following command:

Numberic_ls_l

Having learned how to change the file permissions in Linux, it's time to explore one more dimension, that is, changing the file and the group ownership in Linux.

Q. How to Change File and Group Ownership in Linux?

A. Ownership of files and groups plays a crucial role in managing access and permissions in Linux. In this section, let's explore how to change ownership in Linux.

Change File Ownership

Changing the ownership of a file allows you to transfer the control and responsibility of the file to a different user.

Here's a simple process to change file ownership:

  1. Identify the file for which you want to change ownership. Let's take the file myfile.txt. You can use the ls -l command to view the current ownership details. How to Change File and Group Ownership in Linux
  2. Determine the new owner of the file. You can either use the user's username or their user ID (UID).
  3. Use the chown command followed by the new owner and the file name to change the ownership. For example, to change the owner to chris execute the following command:
 ![How to Change File and Group Ownership in Linux](https://www.scaler.com/topics/images/how-to-change-file-and-group-ownership-in-linux-2.webp)

4. Verify the ownership change using the ls -l command to ensure the new owner is reflected correctly. How to Change File and Group Ownership in Linux

Change Group Ownership

Changing the group ownership of a file determines which group has specific access and permissions to the file.

To change the group ownership of a file in Linux, you can use the chgrp command.

Follow these steps to change the group ownership:

  1. Identify the file for which you want to change the group ownership. Again, the ls l command can help you view the current group ownership.
    How to Change File and Group Ownership in Linux
  2. Determine the new group for the file. You can use the group's name or group ID (GID).
  3. Use the chgrp command followed by the new group and the file name to change the group ownership. For example, to change the group ownership to chris for a file named myfile.txt:
![How to Change File and Group Ownership in Linux](https://www.scaler.com/topics/images/how-to-change-file-and-group-ownership-in-linux-5.webp)

4. Verify the group ownership change using the ls -l command to ensure the new group is displayed correctly. How to Change File and Group Ownership in Linux

Changing file and group ownership simplifies file management and collaboration.

Learn More

To deepen your understanding of file permissions and related concepts, you can explore the following Scaler Topics articles:

Conclusion

Congratulations! You have now gained valuable knowledge about file permission in Linux and how to manage them effectively.

Below are the key takeaways from the article:

  • By learning how to change file permissions in Linux, you can ensure the appropriate level of security and control for your files.
  • The ls command displays detailed information about the file's owner, group, and access permissions.
  • GUI-based file managers provide a user-friendly interface to view and modify file permissions
  • You can change file permissions in Linux using the chmod command with the symbolic method or the octal/numeric method.
  • The chown command is used to change the ownership of a file, while the chgrp command modifies the group ownership.

In conclusion, by effectively managing file permission in Linux, you can control access to sensitive files, ensure good collaboration within groups, and maintain the security of your system.