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.

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

1 Answer 1

up vote 1 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
    
Do you know why all of those have leading zeros? –  Blacklight Shining Aug 13 '12 at 10:31
1  
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
    
Ah, I'd forgotten (again) that octal values in C have to have leading zeroes. Thanks! –  Blacklight Shining Aug 14 '12 at 12:17

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.