Created
October 22, 2014 12:40
-
-
Save cabo/af42e396566a3ab4b0bb to your computer and use it in GitHub Desktop.
Top 10 space-eating subdirectories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
MULT = { "" => 1, | |
"B" => 1, | |
"K" => 1024, | |
"M" => 1024*1024, | |
"G" => 1024*1024*1024, | |
"T" => 1024*1024*1024*1024, | |
} | |
def hrtonum(s) | |
m = s.match(/^\s*([0-9.]+)(\w?)/) | |
m[1].to_f * MULT[m[2]] | |
end | |
IO.popen("find #{ARGV[0]||"."} -depth 1 -print0 | xargs -0 du -sh").each_line. | |
map { |l| v = l.chomp.split("\t", 2); v[2] = hrtonum(v[0]); v}. | |
sort_by { |a| -a[2]}[0..9].each { |f| | |
puts "%4s: %s" % [f[0], f[1]] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment