0

The following description is from man 2 open in linux system. Sometimes they put two zeros and sometimes three in the front. But I think one zero is good enough. What's the idea behind this?

          S_IRWXU  00700 user (file owner) has read, write, and execute permission

          S_IRUSR  00400 user has read permission

          S_IWUSR  00200 user has write permission

          S_IXUSR  00100 user has execute permission

          S_IRWXG  00070 group has read, write, and execute permission

          S_IRGRP  00040 group has read permission

          S_IWGRP  00020 group has write permission

          S_IXGRP  00010 group has execute permission

          S_IRWXO  00007 others have read, write, and execute permission

          S_IROTH  00004 others have read permission

          S_IWOTH  00002 others have write permission

          S_IXOTH  00001 others have execute permission

          According to POSIX, the effect when other bits are set in mode is unspecified.  On Linux, the following bits are also honored in mode:

          S_ISUID  0004000 set-user-ID bit

          S_ISGID  0002000 set-group-ID bit (see stat(2))

          S_ISVTX  0001000 sticky bit (see stat(2))
K.Miao
  • 811
  • 7
  • 21
  • 2
    The description relates to a specific number of bits that represent file permissions. The first leading zero indicates octal, but the other zero indicate empty permission bits and are there for to make the bit value easier to read. – Myst Jan 27 '18 at 23:42
  • 4
    One zero is sufficient; using more than one allows the numbers to line up better. – Jonathan Leffler Jan 27 '18 at 23:44
  • Two zeroes is a bit safer. If you accidentally delete one, you're still left with octal. Some beginners use up to four leading zeroes. In competitive coding competitions redundant zeroes are usually banned in the advanced leagues. – Kerrek SB Jan 28 '18 at 00:02

0 Answers0