The result of running `chmod 7` on a file

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 and 777 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 number 007, is just octal 7. The octal number 755 is just a number, and is equivalent to 493 in decimal.
Now how you differentiate an octal number from any other base is that octal numbers are prefixed with a 0. So to say 755 is octal, you should really refer to it as 0755. The chmod 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:

111111111111 - 12 binary bits
============
           1 - Other execute
          1  - Other write
         1   - Other read
        1    - Group execute
       1     - Group write
      1      - Group read
     1       - User execute
    1        - User write
   1         - User read
  1          - Sticky bit
 1           - Set group ID
1            - Set user ID

Note that there are 3 bits for each of "other", "group", & "user". Binary 111 is 7, 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 binary 111. 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.

Related Question