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 40
s and 100
s mean?
1 Answer
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.
-
2They'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) Aug 13, 2012 at 23:23
stat
uses symbolic (drwx
) output on my system. How are you calling it?which stat
?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?