Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
This is a good question, so I tried to generalize it a bit – Michael Mrozek Feb 4 '11 at 16:54
The 'fourth chmod octal digit' is a bit confusing, the digit in question is actually the first when reading from left to right. – jsbillings Feb 4 '11 at 17:05
@jsbillings Fixed, thanks – Michael Mrozek Feb 4 '11 at 17:29
up vote 23 down vote accepted

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.

share|improve this answer
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. – Chris Johnsen Feb 5 '11 at 1:17

Your Answer


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.