how to

How to View File Permissions in Linux Using Command

 

All about file permissions in Linux with examples. There are ways to check user permissions on a file in Linux, or you can check directory permissions using a Linux command. You can read below to find out how it’s done.

File permissions determine who can access files and directories on the system and how. We can also say that file permissions determine who can do what and how.

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

File Permissions

  1. Read (p): Read permission is used to access the contents of the file. Users with Read permission can view the contents of the file and folders.
  2. Write (f): Write permission is used to change or modify the contents of a file or folder.
  3. Run (x): Execute permission allows you to execute the contents of a file or execute a file, such as a script or program.

Octal File Permission Values ​​in Linux

In Linux, a three-digit value represents specific file permissions, and these digital values ​​are known as octal values. Octal values ​​are numbers in base 8 and use the numbers 0 through 7 to indicate file permissions.

Each number represents the file’s read, write, and execute permissions for the owner, group, and others, respectively.

Each permission is assigned a numeric value that has the following meaning:

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

See the table below:

Octal value File permission set File Permissions Description
0 No permissions
1 -X Execute permission only
2 -sh- Write permission only
3 -wx Write and Execute Permissions
4 R- Read-only permission
5 reception Read and execute permissions
6 rv- Read and Write Permissions
7 rwx Read, Write, and Execute Permissions

Let’s look at this with an example: in the resolution value 744, the first digit (7) corresponds to the user, the second digit (4) to the group, and the third digit (4) to the rest.

By summing the values ​​of each user classification (7, 4 and 4), you can find out the file permissions.

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

For better understanding, see the following explanation:

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

How to Check File Permissions Using Linux Command

The ls command, along with the -l option, displays metadata, including file permissions.

$ ls -l

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

File permissions are represented by three characters: “r”, “w” and “x”. If the letters are present, it means the permission is enabled, and when these letters are missing, it means the permission is disabled.

Access rights to a file or directory are assigned to three different categories of users – owner, group, and others. These users are identified by letters: u for user owner, g for group owner, and o for others.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button