Categories
blog howto linux server

DUF alias for sorted du -h

Show disk usage (human readable) for each folder/file sorted by size!

alias duf='du -sk * | sort -n | perl -ne '\''($s,$f)=split(m{\t});for (qw(K M G)) {if($s<1024) {printf("%.1f",$s);print "$_\t$f"; last};$s=$s/1024}'\'
Usage: duf

Alternative without perl:
du -sk * | sort -n | while read size fname; do for unit in k M G T P E Z Y; do if [ $size -lt 1024 ]; then echo -e "${size}${unit}\t${fname}"; break; fi; size=$((size/1024)); done; done


Tested on: Linux (Redhat, Centos, Debian), Unix (Solaris, SunOS)
Author: http://www.earthinfo.org/linux-disk-usage-sorted-by-size-and-human-readable/

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.