Doing chmod 755 on a directory gives me drwxr-xr-x. Should it not give me drwxr-xr-xr since 5 is read,execute?

And Doing chmod 751 on a directory give me drwxr-x--x. Should that not give me drwxr-xr-x?

Kindly explain.

migrated from stackoverflow.com Feb 15 '11 at 10:14

This question came from our site for professional and enthusiast programmers.

The bits are groups of three the results are correct, I do not really get the point you misunderstood. 5 is read, execute but the order of rwx does not change. Consider them as switches, they might be on (r/w/x) or off (-). Here again an overview of the values:

7(8) = 111(2) => rwx
5(8) = 101(2) => r-x
1(8) = 001(2) => --x
  • it is clear to me now. thank you. – Anonymous Feb 14 '11 at 20:54

Answer: It's rwx. Read. Write. Execute.

Not wxr or xrw or rxw. It's only one of the 3! different ways of arranging the letters. This may clear up some of your confusion.

Also, chmod works with an octal positional system. Octal represents base 8. Which can be represented using 1 bit with values from 0-7 inclusive - a total of 8, that's why it's called octal.

Unrelated: In binary, three 1's represent 1+2+4 = 7.

Think of it like this.

rwx
111  where 111 is a binary value

1 1 1      (binary)
4+2+1 -> 7 (decimal by position)

So 751 would be rwx r_x __x
                111 101 001 (binary)
                421 401 001 (decimal by position)
                 7   5   1  (decimal equivalent)

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.