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?

link|improve this question

68% accept rate
feedback

1 Answer

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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