Skip to content

Instantly share code, notes, and snippets.

@thenoviceoof
Created July 2, 2012 05:06
Show Gist options
  • Save thenoviceoof/3031206 to your computer and use it in GitHub Desktop.
Save thenoviceoof/3031206 to your computer and use it in GitHub Desktop.
du, but with a graphical bar
import os
import sys
path = sys.argv[1]
# http://stackoverflow.com/a/943921/184159
rows, columns = [int(i) for i in os.popen('stty size', 'r').read().split()]
dir = os.listdir(path)
sizes = [os.stat(d).st_size for d in dir]
big = max(sizes)
for i in range(len(dir)):
print dir[i], sizes[i]
size = int(columns*float(sizes[i])/big)
#from math import log as lg
#if sizes[i]:
# size = int(columns*(lg(sizes[i])/lg(big)))
#else:
# size = 0
if size:
print "#" * size
else:
print "."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment