Skip to content

Instantly share code, notes, and snippets.

@cabo
Created October 22, 2014 12:40
Show Gist options
  • Save cabo/af42e396566a3ab4b0bb to your computer and use it in GitHub Desktop.
Save cabo/af42e396566a3ab4b0bb to your computer and use it in GitHub Desktop.
Top 10 space-eating subdirectories
#!/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