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.

I have a professor who insists on always typing chmod 7777, but I was taught that chmod 777 was the proper convention.

I tried them out on the command line and chmod 777 something.txt yeilds

-rwxrwxrwx   1 home  staff    0 May  6 16:47 something.txt

and chmod 7777 something.txt yields

-rwsrwsrwt   1 home  staff    0 May  6 16:47 something.txt

Which changes the executable fields to s, s and t. I understand 777 because it's 111 111 111 in binary, so its just turning on all the fields, but why would I use 7777 and what does it do differently?

share|improve this question

migrated from stackoverflow.com May 6 '13 at 23:19

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

    
It has to do with the sticky bit. You can check en.wikipedia.org/wiki/Sticky_bit –  fedorqui May 6 '13 at 20:58
    
Also see en.wikipedia.org/wiki/Setuid –  Shobit May 6 '13 at 20:58
2  
And as a warning, there are only very specific situations you need to use it. Why your professor would set it normally without explanation is asking for security issues. –  Phylogenesis May 6 '13 at 21:00

3 Answers 3

up vote 6 down vote accepted

In 7777, the first three bits are the setuid, setgid, and sticky flags. These should only be set under very special circumstances. You're correct that 777 is the more appropriate setting (if you want to make the file both world-writable and world-executable).

And unless the file is an executable program or script, or a directory, you usually shouldn't set the x bits. There's not much harm in doing so, though.

share|improve this answer
    
Good explanation. –  Nakka Chandra Jul 22 at 14:20

There is no reason for a sensible professor to insist setting the setuid/gid and sticky bits so perhaps are you confusing 7777 and 0777.

The permissions being stated as an octal number, the proper convention to represent them is to prepend a 0. This is just like when 0x is used to distinguish an hexadecimal number.

Note that chmod doesn't expect the permissions to be expressed in decimal or hexadecimal so this octal prefix is optional.

share|improve this answer

The leftmost digit is the setuid, setgid, and stickybit digit. The first two set the effective user and group ids of the user opening the file. I don't know what stickybit is.

share|improve this answer

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.