Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I noticed this just now, when using find and stat to get the permissions of all the items in /usr/local/share/locale before I recursively change them. stat shows the permissions in a numeric format that I'm not familiar with—all the directories are 40755 and the files are 100644. I'm guessing that the last three are just normal octal permissions (which I already know about), but what do the 40s and 100s mean?

share|improve this question
    
stat uses symbolic (drwx) output on my system. How are you calling it? which stat? – Daniel Beck Aug 13 '12 at 7:46
    
The full command I used is find /usr/local/share/locale -exec stat -f '%p %N' {} \;. stat is /usr/bin/stat. This is on OS X Mountain Lion; are you on Linux? – Blacklight Shining Aug 13 '12 at 8:02
up vote 3 down vote accepted

stat(1) is primarily a wrapper for stat(2), and the man page of stat(2) reveals this:

 The status information word st_mode has the following bits:

 #define S_IFMT   0170000  /* type of file */
 #define S_IFIFO  0010000  /* named pipe (fifo) */
 #define S_IFCHR  0020000  /* character special */
 #define S_IFDIR  0040000  /* directory */
 #define S_IFBLK  0060000  /* block special */
 #define S_IFREG  0100000  /* regular */
 #define S_IFLNK  0120000  /* symbolic link */
 #define S_IFSOCK 0140000  /* socket */
 #define S_IFWHT  0160000  /* whiteout */
 #define S_ISUID  0004000  /* set user id on execution */
 #define S_ISGID  0002000  /* set group id on execution */
 #define S_ISVTX  0001000  /* save swapped text even after use */
 #define S_IRUSR  0000400  /* read permission, owner */
 #define S_IWUSR  0000200  /* write permission, owner */
 #define S_IXUSR  0000100  /* execute/search permission, owner */

So the leading 100 means it's a regular file, and the leading 40 means it's a directory.

share|improve this answer
2  
They're all in octal because octal is convenient for the low 9 bits (rwxrwxrwx) and mixing octal with decimal would be a disaster. (S_IFREG would be 32768, which is sort of a recognizable number, but the combination of that with permission bits 0644 would be 33188, which is much harder to read than 0100644) – Alan Curry Aug 13 '12 at 23:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .