I got it from Nixcraft article here, so here is the source: http://www.cyberciti.biz/faq/how-do-i-find-the-largest-filesdirectories-on-a-linuxunixbsd-filesystem/

I mention this method in finding largest files articles (also sourced from above link):  Largest Files

It looks like this:

So the idea is very simple and works wonders. Here is what this does. The for loop goes thru the Gs first, then the Ms, then the Ks, It sorts them and the end result is they are all concattaned on the screen and sorted from biggest to smallest from G to M to K.

1. take list of numbers and grep out numbers that have “number and G” and sort that
2. Do step one but instead of G use M
3. Do step one but instead of G use K
4. Concatenate the results

2 thoughts on “Linux “Sort” cant sort by human readable sizes – here is a fix – sorting with human readable sizes script

    1. Yes you are correct, “du -h | sort -h”, that is the operation I was trying to duplicate without actually using “sort -h”. You see “sort -h” is not on many linux systems as its only in the newer sort program. Not every system comes with the latest utilities (eg: embedded systems, busybox systems – i.e. your latest Android phone)

Leave a Reply

Your email address will not be published. Required fields are marked *