Getting the size of a directory on the command line?

Here is a function for  .bash_aliases (vi ~/.bash_aliases)

# du with mount exclude and sort
function dusort () {
    DIR=$(echo $1 | sed 's#\/$##')
    du -scxh $(mount | awk '{print $3}' | sort | uniq \
     | sed 's#/# --  exclude=/#') $DIR/* | sort -h
}

source vi ~/.bash_aliases 

sample output:

$ dusort /
...
0       /mnt  
0       /sbin
0       /srv
4,0K    /tmp
728K    /home
23M     /etc
169M    /boot  
528M    /root
1,4G    /usr
3,3G    /var
4,3G    /opt
9,6G    total

for subdirs:

$ dusort .
$ dusort /var/log/
(Visited 3 times, 1 visits today)

Leave A Comment

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