Is there any difference between mode value 0777 and 777

If you're passing them to chmod (the command-line program), there is no difference. But in a C program or similar, 0777 is octal (three sets of three 1 bits, which is what you intend), while 777 is decimal, and it's quite a different bit pattern. (chmod will interpret any numeric argument as octal, hence no leading zero is necessary.)

0777 (octal)    == binary 0b 111 111 111    == permissions rwxrwxrwx   (== decimal 511)

777 (decimal) == binary 0b 1 100 001 001 == permissions sr----x--x (== octal 1411)


The first bit is used for the sticky bit http://en.wikipedia.org/wiki/Sticky_bit

If you set permission using 4 digits, the first will set or remove this bit.

Tags:

Permissions