Quick Disk Usage Bash Script

Posted on .

The command, du (estimate file space usage) is a core Linux program I use often.

When trying to find where space is being used on a disk I run the following command:

du --max-depth=1 -xh

This produces a list of all directories with their total size in human readable format. However it isn’t sorted, and it doesn’t tell me how much is being used in the current directory.

So I wrote a script which lists the directory sizes in human readable format, sorts them by size, and also has a seperate entry for the current directory, along with total.

Typical output:

$ ddu
0K ./proc
0K ./run
0K ./sys
4K [.]
4K ./boot
4K ./data
4K ./dev
4K ./lib64
4K ./media
4K ./mnt
4K ./opt
4K ./selinux
4K ./tmp
12K ./srv
32K ./home
76K ./root
5.5M ./sbin
5.5M ./bin
5.7M ./etc
12M ./lib
341M ./var
761M ./usr
--
1.1G [total]

 
Download
  ddu.sh (846 bytes, 1,511 hits)

Leave a Reply

You may leave the Name and Email fields blank to post anonymously.