Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

File permissions in UNIX are frequently specified as an octal number. Why is octal the preferred base for this purpose?

share|improve this question
add comment

2 Answers

up vote 13 down vote accepted

Because the permissions are stored in a bit field, grouped in 3-bit chunks (eg rwx).

Octal is a natural way to describe them because you only need 1 octal digit to exactly represent any sequence of 3 binary digits. (This is similar to why hexadecimal is used in programming -- since 1 hex digit can represent 4 binary digits, you only need 2 hex digits to describe 1 byte. It boils down to the fact that 8 and 16 are powers of 2, so converting between octal and binary or hexadecimal and binary is really easy.)

These chunks are user (aka owner), group and others. Each chunk has three permissions to describe: read, write, and execute.

Hence the full set of permissions looks something like rwxrwxrwx, where each is a binary digit. So, for example, 110100100 in binary becomes 644 in octal, and you know that the first octal digit is for the owner's permissions, the second for the group's permissions, and the third for everyone else.

share|improve this answer
    
Traditionally user, group and other (not owner). The alternate syntax for chmod would be "chmod u+x file", read as "allow the user to execute this file." –  CarlF Jan 31 '10 at 6:20
    
fixed. pavium, ya beat me to the punch so i added the points i was going to make into your answer. good job. –  quack quixote Jan 31 '10 at 6:22
    
@~quack, thanks very much for the clarification and the comment. 'chunks' is a better word... makes more sense this way. –  pavium Jan 31 '10 at 9:23
add comment

There are three different classes specified by permissions on an object: Owner, group, and everyone else. Each of these classes has three independent permissions that can be set: read, write, and execute. This means each class has one of eight permission sets:

  1. Execute
  2. Write
  3. Write/execute
  4. Read
  5. Read/execute
  6. Read/write
  7. Read/write/execute
  8. No permissions

Since an octal digit takes one of eight different values (the numbers 0 through 7), you can represent any combination of read/write/execute with a single octal digit.

Internally, the computer stores permissions as a bit field. So, for example, if you set permissions to 644, the computer might represent this as the binary number 110100100, or:

 110  |  100  |  100
 rw-  |  r--  |  r--
  6   |   4   |   4
Owner | Group | World

(Notice that binary 110 is equal to octal 6, and binary 100 is equal to octal 4).

share|improve this answer
    
the eight possible settings is true, but incidental. we don't really consider all the different possibilities there -- the system sees it as a field of independent bits, and adds the bits together only when converting to an octal representation. –  quack quixote Jan 31 '10 at 6:26
    
This is true, but I figured mapping bits might be a little tougher to understand for someone not already familiar with it. I did add it below. –  Stephen Jennings Jan 31 '10 at 6:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.