Skip to content

Instantly share code, notes, and snippets.

@brettlangdon
Created October 15, 2015 20:30
Show Gist options
  • Save brettlangdon/538c9757da60fcb53313 to your computer and use it in GitHub Desktop.
Save brettlangdon/538c9757da60fcb53313 to your computer and use it in GitHub Desktop.
Human friendly octal file modes
import os
import stat
import mode
passwd_stat = os.stat('/etc/passwd')
passwd_mode = stat.S_IMODE(passwd_stat.st_mode)
print passwd_mode
# 420
print passwd_mode == (mode.USER_RW | mode.GROUP_R | mode.OTHER_NONE)
# True
import stat
USER_RWX = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
USER_RW = stat.S_IRUSR | stat.S_IWUSR
USER_RX = stat.S_IRUSR | stat.S_IXUSR
USER_WX = stat.S_IWUSR | stat.S_IXUSR
USER_R = stat.S_IRUSR
USER_W = stat.S_IWUSR
USER_X = stat.S_IXUSR
USER_NONE = 0
GROUP_RWX = stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP
GROUP_RW = stat.S_IRGRP | stat.S_IWGRP
GROUP_RX = stat.S_IRGRP | stat.S_IXGRP
GROUP_WX = stat.S_IWGRP | stat.S_IXGRP
GROUP_R = stat.S_IRGRP
GROUP_W = stat.S_IWGRP
GROUP_X = stat.S_IXGRP
GROUP_NONE = 0
OTHER_RWX = stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH
OTHER_RW = stat.S_IROTH | stat.S_IWOTH
OTHER_RX = stat.S_IROTH | stat.S_IXOTH
OTHER_WX = stat.S_IWOTH | stat.S_IXOTH
OTHER_R = stat.S_IROTH
OTHER_W = stat.S_IWOTH
OTHER_X = stat.S_IXOTH
OTHER_NONE = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment