Skip to content

Instantly share code, notes, and snippets.

@Atticuss
Last active February 23, 2016 17:21
Show Gist options
  • Save Atticuss/d93d52d3e7505c6e345b to your computer and use it in GitHub Desktop.
Save Atticuss/d93d52d3e7505c6e345b to your computer and use it in GitHub Desktop.
import sys,os
from stat import *
if len(sys.argv) < 2:
print('Usage: python fileperms.py <dir>')
sys.exit(1)
flist=[]
for (dirpath,dirname,filenames) in os.walk(sys.argv[1]):
flist.extend(['%s/%s'%(dirpath,filename) for filename in filenames])
readable=0
writable=0
executable=0
for f in flist:
if os.stat(f)[ST_MODE] & 4 != 0:
print('world readable file: %s'%f)
readable += 1
if os.stat(f)[ST_MODE] & 2 != 0:
print('world writable file: %s'%f)
writable += 1
if os.stat(f)[ST_MODE] & 1 != 0:
print('world executable file: %s'%f)
executable += 1
print('\nTotal files: %s'%len(flist))
print('World readable: %s'%readable)
print('World writable: %s'%writable)
print('World executable: %s'%executable)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment