Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

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.