Reputation: 1445
I'm trying to understand the permission system of Linux. I understand the groups:
owner (u)
group (g)
others (o)
and the permission types:
read (r = 4)
write (w = 2)
execute (x = 1)
(I've read something about setuid/setgid
and sticky bit
and I don't really understand what they are good for.)
The other thing I don't understand for example in PHP the 5 digits of permission instead of 3: So what does this do?
mkdir($directory, 02770);
277
Should mean write perm for the owner, and everything for the group and other users, but what does the first and last digit mean?
Upvotes: 2
Views: 2045
Reputation: 19
late but here is the answer to your last question: Bits 11...9 stand for SUID, SGID, Sticky, this info can be easily found. But there are altogether 16 permission bits. Bits 15...12 code the type of "file": 0001=p=fifo (pipe), 0010=c=character device, 0100=d=directory, 0110=b=block device, 1000="normal" file, 1010=l=link (soft link file), 1100=s=socket According to this, the "4" simply says "directory".
Upvotes: 1
Reputation: 40894
More about setuid, setgid, and sticky bit in Wikipedia.
The constant is shown as 5-digit but the first digit is always 0
; it is a convention for octal literals (that is, 010
is 8, not 10). This makes sense because 8-base numbers have digits representing exactly 3 bits, and the permission bits are grouped by 3. (This made a lot more sense on old PDP machines that used octal all around, especially in the machine code presentation, and were the original hotbed of Unix development. On Intel and ARM, hex numbers are common, so octals are not instantly recognized for what they are.)
Upvotes: 2