The chmod command can also be used to modify file or directory permissions, using the numeric method. This method sets exactly the new permissions specified, using numbers with the chmod command, irrespective of the existing permissions of the file or directory. In the numeric method, permissions are represented by three-digit (or four-digit when setting special permissions) octal numbers. Each octal number represents a number between zero and seven, which is the sum of permissions for an access level—either a user, group, or others. The syntax to apply permissions using numbers is as follows:
$ chmod ### file | directory
Here, each # represents permissions for a user, group, and other access levels, starting from left to right. It is the sum of all the permissions (read, write, and execute) of that access level, where each permission has a certain numeric weightage, as follows:
Here is a table listing the numeric weightage of permissions:
Permission |
Numeric weightage |
Read (r) |
4 |
Write (w) |
2 |
Execute (x) |
1 |
When setting permissions using the numeric method, we calculate the total sum of permissions we need for the user, group, or others; for example, if you want to use set-rwx-r-xr-- as the new permission for file1, you do the following:
user → rwx → 4+2+1=7
group → r-x → 4+1=5
others → r- - → 4=4
The following example of the chmod command shows the usage of the chmod to set permissions using numbers and the usage of chmod to set the same permissions using symbols:
$ chmod 754 file1
$ chmod u=rwx,g=rx,o=r file1
The following are some examples to illustrate the usage of the chmod command using numbers:
Set the read permission for the user, the write permission for the group, and no permission for others on the file named file1, as shown in the following screenshot: