9

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?

14

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.

  • Good explanation. – Chandra Nakka Jul 22 '14 at 14:20
  • What, exactly, do those tags do? When do I want to use the setuid, setgid, and sticky flags? Does using them when they shouldn't be used cause problems? – Aaron Franke Dec 16 '16 at 21:42
  • They have different meanings depending on whether you're setting them on a file or directory, and whether the file is executable or not. Whether they cause problems depends on the specifics. Most of the time they aren't needed. Google them to find out what they do, I'm not going to try to explain all the details here. – Barmar Dec 16 '16 at 21:46
1

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.

  • 2
    He was a physics professor so that may have been the issue – Loourr Oct 8 '17 at 2:16
  • @Loourr Well, being a physics professor is not per se an issue ;-) I guess you actually mean that professor was not a computer science one. It might indeed be the reason of the wrong advice. – jlliagre Oct 8 '17 at 10:17
0

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.

-1

The sticky bit is used to tell the operating system to keep the file in RAM as much as possible to reduce reads from disk and reduce latency. This is applied to files that are sued often and needed with high immediacy. Some OS's and software systems ignore it or use other methods to accomplish the same thing. But that is where the sticky name comes from (keep it stuck in memory whenever possible)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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