Super User is a question and answer site for computer enthusiasts and power users. 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

Found the following PHP code today:

mkdir($directory, 02777);

chmod($directory, 02777);

I understand the PHP, but not first part of those numbers. The 777 part is clear, and if I have understood correctly the 0 just means it's octal. But what does the 2 in there do?

Also, if I changed it to 02640, would the 2 still do whatever it does, or does it change according to what comes after it?

share|improve this question
up vote 5 down vote accepted

This octal digit is made up of setuid, setgid and sticky bits, all of which have comparatively complex effects.

The 2 sets the setgid flag. When present on a directory, all files created within it will inherit its group, instead of the creating user's primary group.

More on Wikipedia.

share|improve this answer

You must log in to answer this question.

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