Whats the difference between chmod 777 and chmod 7777

chmodunix

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?

Best Answer

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.

Related Question