Wednesday, December 26, 2012

File Permissions in Unix - Numeric Representation

chmod 777 file_name - gets you full access to everybody in Unix. What does 777 mean?
First digit is OWNER, Second digit is GROUP and the Third is OTHERS.

So, if a file has rwx-x-x which means, Owner can Read, Write an Execute (rwx) and the Group and the Other can only Execute (x). Below chart represents the numbers (like 755, 644) and its meaning.

Octal digit
Text equivalent
Binary value
Meaning
0
---
000
All types of access are denied
1
--x
001
Execute access is allowed only
2
-w-
010
Write access is allowed only
3
-wx
011
Write and execute access are allowed
4
r--
100
Read access is allowed only
5
r-x
101
Read and execute access are allowed
6
rw-
110
Read and write access are allowed
7
rwx
111
Everything is allowed


As you see that "1" stands for execute only, "2" stands for write only, "4" stands for read only. To combine the permissions you can simply add 1, 2 and 4 to get a needed combination. For instance, to get read and write permissions, you add 4 (read) and 2 (write), thus getting 6 (read and write). To get read and execute permissions, you add  4 (read) and 1 (execute), thus getting 5 (read and execute).

PS: Adding this here for my quick reference not that the world doesn't know about it :)