Sorting disk usage (du) output of folder contents

Basic approach is

$ du -hs * | sort -h

And this particular code is useful when having a lot of files/directories in target directory

$ du -h | perl -e 'sub h{%h=(K=>10,M=>20,G=>30);($n,$u)=shift=~/([0-9.]+)(\D)/;
return $n*2**$h{$u}}print sort{h($b)<=>h($a)}<>;'

Keeping it mostly for myself, stole it from:

https://serverfault.com/a/62422

Leave a comment

Design a site like this with WordPress.com
Get started