Octal Permission in Linux

Octal Permission in Linux

Get Efficient & Concise With Permissions in Linux

ยท

5 min read

Prerequisite

To proceed further into reading this article, You need to be familiar with the following:

  • permissions in Linux ( rwx )

  • User categories ( u, g, o, a )

What you're gonna get from this article

In this article, we will simplify the concept of octal numbers and their associated permissions. We will also provide you with a handy trick formula that is not widely known, which will help you easily remember and generate octal mode numbers and their corresponding permissions. With this formula, you won't have to rely on searching the web every time you need octal mode numbers.

Why Learn Octal?

First of all, you all might be wondering, why we even need to learn Octal when we have simpler Symbolic Permissions ( rwx ).

  • The simple answer to this is that you can define the permission of any user category for a file/directory in just 3 digits ---- Meaning, it's way too concise than the Symbolic mode.

Let me show you how:

  • We have two files one for each permission mode.

  • We're going to use Octal mode on OctalFile.txt and

  • Symbolic mode on SymbolicFile.txt

Comparison

  • Permissions of both files are set to none:

  • Now let's use both Symbolic and Octal modes on respective files to assign the same set of permissions ( user= read, write & execute | group= read & write | others= read ) :

    • Using Symbolic mode on SymbolicFile.txt:

    • Now let's use Octal mode on OctalFile.txt:

Comparison summary

  • Do you notice how less we need to write in the Octal when compared to the Symbolic mode?

  • Where we need to write "u=rwx,g=rw,o=r" in Symbolic mode, the same can be done just by using "764" in Octal mode.

  • This makes Octal preferred over Symbolic by advanced Linux users as it's concise and readable.


Let's get into the real thing, shall we?

Let me simplify this Octal mode for you.

Octal mode, as the name suggests, has 8 different digits that represent different sets of permissions ( by set I mean a combination of rwx and "_" which means no permission ).

This ranges from 0 to 7 just as any indexing does in Computers.

Now I know a few or a number of you find it intimidating that's why you end up using Symbolic but wait till the end as the trick that I'll share will get you using it every day.

So in all the 8 digits, you only need to remember 3 ( rwx ) and the rest 5 is a combination of these so you'll be able to map the other 5 easily if you have these 3 in your head:

0 ->
1 -> x    // execute
2 -> w    // write
3 ->
4 -> r    // read
5 ->
6 ->
7 ->

Again, don't get intimidated if you can't remember these three either, just keep reading till the end and you'll get it all at the end.

First, let's see how these three combine to create the other 5 or shall say 4 ( as 0 simply means no permission ).

We're now left with 4 other digits which are 3, 5, 6 and 7, let me explain the combination:

3 -> 1 + 2 -> 1=x + 2=w    // x + w
5 -> 1 + 4 -> 1=x + 4=r    // x + r
6 -> 2 + 4 -> 2=w + 4=r    // w + r

All Permission:
7 -> 1 + 2 + 4 -> 1=x + 2=w + 4=r   // x + w + r

Do you notice how three of the permissions x, w, r which are equivalent to 1, 2 and 4 respectively, combine to form the other 4 in the octal mode?

So this was to explain to you how octal works.

Some people might have grasped and maybe, are now comfortable with using this.

But a few might not, and let me tell you, I fell under the categories of those few until I found a trick formula that makes it easy to remember. So here I go into explaining that to you.


The Trick Formula

So here it is:

Don't get intimidated by it either, it would appear to be complex to some but let me explain and then you will remember it forever.

Let's break this down:

  • First, remember that the base is always 2 ( observe the first row ).

  • Second, the power of base 2 i.e., 0, 1 and 2 ( because there are 3 permissions- rwx ).

  • Third, "least is the most rule"

    • When I say least, I refer to 0 from 0, 1 and 2 powers. Or 1 when considered 1 and 2.

    • And when I most that's when I am referring to the impact or strength of permission ( execute is the highest impactful permission as you're letting a person execute stuff on your system )

So 2^0 is the least so it is going to the most powerful permission i.e., x ( execute permission ).

2^1 is in the middle so it's gonna be w ( write permission ) as it's more impactful than read ( r ) but less impactful than x ( execute ).

2^2 is exactly opposite to "least from Least is the most rule" then it's gonna be r ( read permission ).

And that's it, you have it now.


I hope I was able to explain this thoroughly and well enough to you all.

I have one request for you all, please consider giving me feedback on my delivery or any other stuff that you might feel needs improvement.

A big Thanks for Reading this!!

Did you find this article valuable?

Support Anand Darshan by becoming a sponsor. Any amount is appreciated!