I saw a code change at work, where the mode values were changed from 777 to 0777 to make nfs setattr work. What is the difference in the 2 values?
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
777 (decimal) == binary
0b 1 100 001 001 == permissions
sr----x--x (== octal
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.
The interesting answer is:
- there is no difference between
700, as explained in the other answers
- but there is a difference between
At least that's the case for GNU coreutils' chmod version, which is the default on Linux.
See this example:
$ ls -ld mydir drws--s--- 4 myuser mygroup 4096 Jul 8 09:27 mydir $ chmod 0710 mydir ; ls -ld mydir # surprise ahead -- s-bits remain: drws--s--- 4 myuser mygroup 4096 Jul 8 09:27 mydir $ chmod 00710 mydir ; ls -ld mydir # _now_ they're gone: drwx--x--- 4 myuser mygroup 4096 Jul 8 09:27 mydir
This is to avoid accidental deletion of setuid/setgid bits for directories. For details, see the chmod documentation.
In Linux system there are two types permissions are available:
- File Permission
- Special Permission
In File permission we set permission on files and folders:
The permissions are:
While in special permission three types of permission are:
- Sticky Bit(1)
In your question you ask what is difference, so there is no any difference between
chmod 777 and 0777 because there is
no any octal value which show value of (0) zero.