Why does the Unix permission system use 1 2 3 4... values instead of 1 or 0?
Solution 1:
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
Solution 2:
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.)
Solution 3:
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.