I know chmod 777
allows read, write, and execute for user, group, and others
but what if I just do chmod 7
?
Is that only rwx
for the user?
chmodfiles
I know chmod 777
allows read, write, and execute for user, group, and others
but what if I just do chmod 7
?
Is that only rwx
for the user?
Best Answer
Ramesh's answer is perfectly accurate, but I wanted to chime in and provide a more in depth explanation of file modes.
While numbers like
755
and777
may seem special and only mean something for file modes, they're actually pretty basic.These numbers are actually octal numbers. Decimal numbers are base-10, hex numbers are base-16, binary is base-2, and octal numbers are base-8. Meaning that as you count, you go
1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 20 ...
. So the number007
, is just octal7
. The octal number755
is just a number, and is equivalent to493
in decimal.Now how you differentiate an octal number from any other base is that octal numbers are prefixed with a
0
. So to say755
is octal, you should really refer to it as0755
. Thechmod
command just assumes that all input numbers are octal since that is the most common way of referring to file modes.Now, why do file modes use octal? Well first we need to understand that the mode is just a bitmask that looks like this:
Note that there are 3 bits for each of "other", "group", & "user". Binary
111
is7
, which is the highest single digit octal value. So by using octal numbering, each of the other, group, & user permissions gets a single digit, plus an extra digit for the sticky+setuid+setgid.So with this, we can go back to your original question of "what is
chmod 7
"?Well, now that we know it's just a octal number, and that it's just a bitmask, we can figure this out. Octal
7
is binary111
. Using the above bit positions, we can determine that this sets all 3 of the 'other' bits, granting 'other' execute, read, & write access. And since this is just a number, all the other bits are 0, and become unset.