Chmod Numeric Permissions Notation Linux / Unix

Chmod Numeric Permissions Notation Linux / Unix

In Linux and Unix, you can use the chmod command to change the permissions of a file or directory. The permissions can be represented using a numeric notation, which consists of three digits representing the permissions for the owner, group, and other users, respectively.

The first digit represents the permissions for the owner of the file or directory. The second digit represents the permissions for the group that the file or directory belongs to. The third digit represents the permissions for all other users.

Each digit is made up of three bits, with each bit representing a specific permission:

  • Read (r): 4
  • Write (w): 2
  • Execute (x): 1

To calculate the numeric permissions value, you can add up the values of the permissions you want to set. For example, to give the owner read and write permissions (rw), the group read and execute permissions (rx), and other users read permissions (r), you can use the following numeric notation:

ref‮t re‬o:lautturi.com
644

This is calculated as follows:

  • Owner (rw): 4 + 2 = 6
  • Group (rx): 4 + 1 = 5
  • Other (r): 4

To set the permissions using the chmod command, you can use the -R option to specify that the change should be applied recursively to all files and directories in the specified directory, and the -v option to display a message for each file processed.

chmod -Rv 644 directory

This will recursively change the permissions of all files and directories in the directory to 644.

You can also use the symbolic notation to specify the permissions, using characters to represent the permissions for the owner, group, and other users. For example, to give the owner read and write permissions, the group read and execute permissions, and other users read permissions, you can use the following symbolic notation:

u=rw,g=rx,o=r

This can be set using the chmod command as follows:

chmod -Rv u=rw,g=rx,o=r directory

Keep in mind that the chmod command can only be used to change the permissions of files and directories that you have the permissions to modify.

Created Time:2017-10-28 14:02:23  Author:lautturi