62

Sometimes I see chmod commands that use four octal digits instead of three -- what is the optional first digit for? For example, chmod 777 is equivalent to chmod a+rwx; what's the same command for chmod 2777?

3
  • 1
    This is a good question, so I tried to generalize it a bit Commented Feb 4, 2011 at 16:54
  • 3
    The 'fourth chmod octal digit' is a bit confusing, the digit in question is actually the first when reading from left to right.
    – jsbillings
    Commented Feb 4, 2011 at 17:05
  • 1
    How have only 50 people wondered this same question?
    – Brain2000
    Commented Mar 7, 2021 at 20:25

1 Answer 1

62

Please note that chmod 777 filename is the equivalent of chmod 0777 filename in this example.

The first octal digit sets the setuid, setgid and sticky bits (see this article for more details on setuid/setgid). octal 2 means to set group ID on the file. So, the equivalent would be to do a chmod a+rwx filename, then chmod g+s filename. The chmod info page does explain this in more detail.

1
  • 7
    Nearly all implementations of chmod(1) can use commas in symbolic mode arguments. Thus, your equivalent of 2777 can be done in one command: chmod a+rwx,g+s filename. Or, more strictly (being sure to clear the setuid and sticky bits as the numeric mode would): chmod a=rwx,g+s filename. Commented Feb 5, 2011 at 1:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .