List and sort size of directories in linux

There has always been a lots of need for something like this. So now I FINALLY went and wrote this very simple script. I am very surprised that I have not been able to find this using google, or that this kind of feature would not already exist in du-command.

Short and simple “script” to list sizes of directories without listing their whole content on the screen:

#!/bin/bash

dir="."
if [ "$1" != "" ]; then
 dir="$1"
fi

find "$dir" -maxdepth 1 -type d -exec du -hs "{}" \;|sort -h

Leave a Reply

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