Script to sort & show directory sizes in Linux

Just change /www/htdocs/ to the desired directory that you want to see the subdirectory sizes for, sorted by size descending.

#!/bin/bash
du -k /www/htdocs/* | sort -nr | awk '
     BEGIN {
        split("KB,MB,GB,TB", Units, ",");
     }
     {
        u = 1;
        while ($1 >= 1024) {
           $1 = $1 / 1024;
           u += 1
        }
        $1 = sprintf("%.1f %s", $1, Units[u]);
        print $0;
     }
    ' > filesize.txt