Since Mac OS X doesn't have the -h option for sort (I was probably using Mavericks or Yosemite), so I tried and learned sed and awk for a first attempt:
du -sk * | sort -g | awk '{ numBytes = $1 * 1024; numUnits = split("B K M G T P", unit); num = numBytes; iUnit = 0; while(num >= 1024 && iUnit + 1 < numUnits) { num = num / 1024; iUnit++; } $1 = sprintf( ((num == 0) ? "%6d%s " : "%6.1f%s "), num, unit[iUnit + 1]); print $0; }'
it is a long line. Expanded, it is:
du -sk * | sort -g | awk '{ numBytes = $1 * 1024; numUnits = split("B K M G T P", unit); num = numBytes; iUnit = 0; while(num >= 1024 && iUnit + 1 < numUnits) { num = num / 1024; iUnit++; } $1 = sprintf( ((num == 0) ? "%6d%s " : "%6.1f%s "), num, unit[iUnit + 1]); print $0; }'
I tried it on Mac OS X Mavericks, Yosemite, Ubuntu 2014-04 with awk being the default awk (which is nawk, because both awk and nawk point to /usr/bin/mawk) or gawk, and they all worked.
Here is a sample of the output on a Mac:
0B bar 0B foo 4.0K wah 43.0M Documents 1.2G Music 2.5G Desktop 4.7G Movies 5.6G VirtualBox VMs 9.0G Dropbox 11.7G Library 21.2G Pictures 27.0G Downloads
instead of du -sk *, I saw in @Stefan's answer where the grand total is also displayed, and without traversing any filesystem mount point, by using du -skcx *
sort -hworked for me in Ubuntu 16.04 LTS in Aug 2017. First I find my mounted drive bycd /mnt(mounted by UUID in fstab). Then I dodu >~/dumnt.outthensort -h ~/dumnt.out >~/dumntsort.outthen I can do `tail ~/dumntsort.out to see the largest space hogs.