DEV Community

Nadim Chowdhury
Nadim Chowdhury

Posted on

What is chmod numbers in linux?

In Linux, chmod is a command used to change the permissions of files and directories. Permissions determine who can read, write, and execute a file.

The permissions are represented by three groups: owner, group, and others. Each of these groups has three types of permissions: read (r), write (w), and execute (x).

To change permissions using chmod, you can use either symbolic mode or numeric mode. In numeric mode, permissions are represented by three octal digits:

  1. The first digit represents the permissions for the owner.
  2. The second digit represents the permissions for the group.
  3. The third digit represents the permissions for others.

Each digit is a combination of the following values:

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

You add these values together to assign permissions. For example:

  • 7 = 4 (read) + 2 (write) + 1 (execute) = full permissions (rwx)
  • 6 = 4 (read) + 2 (write) = read and write permissions (rw-)
  • 5 = 4 (read) + 1 (execute) = read and execute permissions (r-x)
  • 4 = 4 (read) = read-only permissions (r--)
  • 0 = No permissions (--)

So, when you use chmod with numeric mode, you specify the desired permission using these digits. For example, to give read, write, and execute permissions to the owner, read and execute permissions to the group, and only execute permission to others, you would use:

chmod 751 filename
Enter fullscreen mode Exit fullscreen mode

This would set the permissions as follows:

  • Owner: rwx (7)
  • Group: r-x (5)
  • Others: --x (1)

Disclaimer: This article was created with the help of AI.

Top comments (0)