Skip to content

Instantly share code, notes, and snippets.

@jewel12
Created March 21, 2011 13:09
Show Gist options
  • Save jewel12/879426 to your computer and use it in GitHub Desktop.
Save jewel12/879426 to your computer and use it in GitHub Desktop.
du -h の結果をソートする
# coding:utf-8
# du -h の結果をソート
# usage: du -h | ruby du_sort.rb
results = []
while l=STDIN.gets
size_h = l.split("\t")[0]
m = 1
case size_h[-1].chr
when "K"; m=1000
when "M"; m=1000**2
when "G"; m=1000**3
end
results << [ size_h[0..-2].to_i*m, l ]
end
results.sort{|a,b| b[0] <=> a[0] }.each{ |e| puts e[1] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment