One of the most common Linux command that we use in our day-to-day life to execute or give permission to a file in Linux system. One way to give permission to a file is through Octal Mode. One of the easiest way set permission on a file. So in this article we are going to learn how to use octal mode.

Octal mode

The word itself says that it use Octal Number System which consist of eight number i.e. 0 to 7 to set permission on file.

Where..

Here is the table of what every number represent in the system :

Octal ValueFile Permissions SetPermissions Description
0- - -No permissions
1- - xExecute permission only 
2- w -Write permission only 
3- w xWrite and execute permissions
4r - -Read permission only
5r - xRead and execute permissions
6r w -Read and write permissions
7r w xRead, write, and execute permissions

Or we can use binary to octal representation. To do so we have to consider r w x value as a switch which have 0 and 1 value.

So if we have to set only read permission i.e. r - - if we convert it into binary where r w x are 1 and - is 0.

So r - - = 1 0 0

Now converting this binary to octal, which is 1 0 0 = 4 and if we see in table i.e. 4 value is equal to Read permission only.

Let’s solve some example to have better understanding of octal mode :

  1. Read permission to only Owner i.e. r-- --- ---

    File PermissionBinaryOctal
    Ownerr - -1 0 04
    Group- - -0 0 00
    Other- - -0 0 00

    chmod 400 file.txt will have read only permission to Owner

  2. Read and write permission to Owner and Group i.e. rw- rw- ---

    File PermissionBinaryOctal
    Ownerr w -1 1 06
    Groupr w -1 1 06
    Other- - -0 0 00

    chmod 660 file.txt will have read and write permission to Owner and Group only.

  3. Read, write and execute permission to everyone i.e. rwx rwx rwx

    File PermissionBinaryOctal
    Ownerr w x1 1 17
    Groupr w x1 1 17
    Otherr w x1 1 17

    chmod 777 file.txt will have access to every one.

This is how we use Octal mode in Linux to setup a file permission in Linux file system. It seems difficult for the first time but if we understand the concept, it is very easy to implement it on Linux file system.