1

Why does the Unix permission system use 1 2 3 4... values?

Why not just 3 bits; a bit for each setting read write and execute. for example

( rwx ) 110 => r=1 w=1 x=0
Zanna
  • 70,465
aliarousyoucef
  • 531
  • 1
  • 6
  • 14

3 Answers3

5

It's more compact to use integers from 1-7 that are the sum of the following three octal permission representation numbers, 4 (read), 2 (write), and 1 (execute) added together, because all the Unix permissions can be represented by one integer number ranging from 1 to 7 instead of using 3 numbers to represent the Unix permissions.

Usage examples

Number  Octal Permission Representation                            Ref
0       No permission                                              ---
1       Execute permission                                         --x
2       Write permission                                           -w-
3       Execute and write permission: 1 (execute) + 2 (write) = 3  -wx
4       Read permission                                            r--
5       Read and execute permission: 4 (read) + 1 (execute) = 5    r-x
6       Read and write permission: 4 (read) + 2 (write) = 6        rw-
7       All permissions: 4 (read) + 2 (write) + 1 (execute) = 7    rwx
karel
  • 114,770
5

Because we have these 3 bits (r/w/x) 3 times, once for user (owner) permissions, once for group permissions and once for permissions for everybody else.

That is why e.g. in the output of ls -l where you get the textual permissions representation, it looks e.g. like -rwxr-xr-x (the first - just indicating the file type, i.e. whether it is a directory or not).

(Actually there are even three more bits - SUID, SGID and Sticky - but you can look those more advanced permissions up on your own if you are interested.)

Byte Commander
  • 107,489
  • 1
    That's exactly it, always remember we are lazy, we don't want to write chmod 111101000 for just changing one files access... That's why they just shortened it and said we use 3 bits per each owner,group and others. So we now have chmod 750 instead which is much nicer. – Ziazis Aug 31 '17 at 11:13
2

To representing rwx it's exactly using 3 (0 or 1) bit:

Decimal  |  Binary
--------------------
1        |    001
2        |    010
3        |    011
4        |    100
5        |    101
6        |    110
7        |    111

So when you are using "3" you are actually setting the bits on: 011 equal to -wx, exactly as you are thinking about it. However don't forget about SUID, SGID and sticky bit as an extra bit.

Ravexina
  • 55,668
  • 25
  • 164
  • 183