Highest disk usage of directory in subdirectories

I find myself doing this lot of times so thought will share this with you all. Basically, once I want to clear out the directory, I first want to find out the sub-directory using the maximum disk space so I wrote a function for that and here it is:


disk_usage_dirs () 
    find . -maxdepth 1 -type d -not -name '.' | while read line; do
        du -s "$line";
    done | sort -n | tail -${1:-5}

Some other posts you might find useful on this :

Disk usage by file type

Color disk usage on Fedora

Get disk usage for all the containers with python script

Disk usage by file type

Trying to find the total usage for each of the file types by extension, then here is a quick bash function for you :

disk_usage_type () 
    find . -name '*'$1 -ls | awk '
    {sum+=$7; files++;}
    print "Total sum is ::\t" sum;
    print "Total files  ::\t" files;
        while (sum > 1024) {
        print sum" "a[count];

Just define the function in one of your bash startup files. After that to use the function pass in the extension for which you would like to find the total size. Output should be something like below:

Total sum is ::    2586694320
Total files  ::    149
2.40905 GB