9

Can anyone tell me what is the meaning of the number from the ST_MODE function?

Example:

>>>import os
>>>stat = os.stat('/home')  
>>>print stat.st_mode  
16877  

it prints 16877. What is that for?

youri
  • 3,446
  • 5
  • 21
  • 39
Egy Mohammad Erdin
  • 3,333
  • 6
  • 32
  • 55

2 Answers2

29

It's the permission bits of the file.

>>> oct(16877)
'040755'

See the various stat.S_* attributes for more info.

Ignacio Vazquez-Abrams
  • 740,318
  • 145
  • 1,296
  • 1,325
  • 3
    AFAIK in addition to permissions, st_mode is for testing whether a file is of a specified type (FIFO, link, etc) – Eli Bendersky Nov 03 '10 at 13:32
  • 2
    For the lazy: the most significant (leftmost) two octal digits specify file type, the four least significant are of course the normal file permissions bits. Get these permissions bits with stat.S_IMODE. – ACK_stoverflow Jul 18 '19 at 19:05
2

The standard stat module can help you interpret these values from os.stat:

The stat module defines constants and functions for interpreting the results of os.stat(), os.fstat() and os.lstat() (if they exist). For complete details about the stat(), fstat() and lstat() calls, consult the documentation for your system.

Eli Bendersky
  • 248,051
  • 86
  • 340
  • 401