How To Check Permissions Of A File In Linux In Numbers

This tutorial explains how to check file permissions in Linux command-line and how to check permissions of a file in Linux in numbers.

Checking file permissions in Linux via the command line allows you to view and modify access controls with precision. File permissions determine who can access files and directories on a system and how. We can also say that file permissions specify who can do what and how.

There are three types of Linux file permissions: read, write, and execute.

File Permissions in Linux

In Linux, file permissions are used to control access to files and directories. In Linux, each file and directory has three types of permissions: read (r), write (w), and execute (x).

These permissions can be assigned to three different user groups: the owner, the group, and others. An owner is the one who created the file, the group consists of other users assigned to the same group, and others refer to any user who does not fall into either of the former categories.

Each file and directory in Linux has three basic permissions: read, write, and execute.

  • Read (r): The read permission gives users the ability to view a file/directory.
  • Write (w): The write permission gives users the ability to modify, delete, and create files/directories.
  • Execute (x): The execute permission gives users the ability to execute files/directories (i.e. run programs).

The permissions can be set for each user (owner), group of users, and all other users (other). The owner is the user who owns the file/directory, the group is a set of users who have the same permissions, and other is all other users who do not belong to the group.

NOTE

  • Read permission is used to access the file’s contents. Users with read permission can view the contents of the file and folders.
  • Write permission is used to modify or change the contents of a file or a folder.
  • Execute permission allows you to execute the contents of a file or to execute a file, such as a script or a program.

File Permission Octal Values in Linux

The numbers are calculated by adding the values of the permissions you want to set:

In Linux, a three-digit value represents specific file permissions and these digital value are known as octal values. Octal values are base 8 numbers and they use the numbers 0 to 7 to represent file permissions. Each number corresponds to the read, write, and execute file permissions for the owner, group, and others, respectively.

Each permission has a numeric value assigned to it with the following meaning:

  • r (read): 4
  • w (write): 2
  • x (execute): 1

Let us understand this by an example, in the permission value 744, the first digit (7) corresponds to the user, the second digit (4) to the group, and the third digit (4) to others. By adding up the value of each user classification (7, 4 and 4), you can find the file permissions.

For example, the first digit (7) corresponds to the user and have read (4), write (2), and execute (1) permissions for its owner (4+2+1=7), and only read permission for all other users (4 for read).

See the following explanation for a better understanding:

  • Owner: rwx = 4+2+1 = 7
  • Group: r– = 4+0+0 = 4
  • Others: r– = 4+0+0 = 4

How to check file permissions in Linux command

The ls command is your friend when you need to check on file permissions. It’s like asking your computer to tell you who can access what in a specific folder or directory.

Just type “ls -l” and you’ll see a list of all files with details about their permissions. The ls command along with its -l shows the metadata including the permissions of the file.

$ ls -l

In Linux, file and folder permissions are represented by a string of ten characters. Where the first character represents the file type, “-” for a file or “d” for a directory. The other nine characters are grouped into sets of three, representing the permissions for the owner, group, and others, to whom these file permissions are assigned.

The file permissions are represented by three characters, “r,” “w,” and “x.” When the letters are present it indicates that the permission is enabled and when these letter are absent it indicates that the permission is disabled.

The file or directory permissions are assigned to three different categories of users – owner, group and others. These users are represented by letters, u for user owner, g for group owner, and o for others.

The first character reveals the file type – with a “-” typically meaning a regular file. After that comes a sequence of 9 letters or dashes that are the actual permission codes: three sets of r, w, and x meaning read, write, and execute access for the file owner, group, and everyone else.

So if you see “rw-r–r–” that means the file owner can read and write to the file, users in the owner’s group can only read, and all other users have no access. The ls command spells all this out for you in an easy-to-decipher format. No need to guess – just ls it!

For a more detailed view of file permissions, you can use “stat” command by executing “stat “. This will retrieve an entire list of file attributes, including the permissions.

Another useful command which can be used for more detailed access, use the getfacl command.

Note that commands such as “chmod”, “chown” and “chrgp” are used to modify and change file permissions. It allows you to add, modify, or remove permissions using numerous combinations of letters and numbers.

Knowing how to check file permissions in Linux command line becomes essential in securing your system and managing your files effectively.

Author: Team Linux Ledger

The team of Linux experts and open source enthusiasts who are passionate about sharing their expertise with you through in-depth tutorials, news, and updates on various aspects of open source in general and Linux in particular A team that helps you become a better Linux user.

Leave a Comment