Diagnosing disk space on Linux

If your disk drive is suddenly full on one of your servers, and you are not using quotas, here is a quick way to diagnose what is using up all of your space.

du -h <dir> | grep '[0-9\.]\+G'

Replace <dir> with the starting directory, if you have a single partition you can just use "/" or you could use df first to see what partition to delve in to.

The grep regular expression will filter the results by anything that is over a Gig.

You can also show the size of a sub-folders and files within a directory, without listing them recursively using the following command. The command below lists the contents of /home/matt. You can follow the large folders to find some large log files or people hosting videos!

du -sh /home/matt/*

4.0K	/home/matt/01-network-manager-all.yaml
3.5G	/home/matt/bin
83M	    /home/matt/core
4.0K	/home/matt/Desktop
7.5G	/home/matt/Documents
74M	    /home/matt/Downloads
1.4G	/home/matt/Dropbox
12K	    /home/matt/examples.desktop
7.6M	/home/matt/gam
53M	    /home/matt/google-chrome-stable_current_amd64.deb
176M	/home/matt/google-cloud-sdk
25M	    /home/matt/google-cloud-sdk-237.0.0-linux-x86_64.tar.gz
4.0K	/home/matt/Music
76K	    /home/matt/net1
21M	    /home/matt/Pictures
4.0K	/home/matt/Public
20K	    /home/matt/response.png
12K	    /home/matt/ScriptedHost
11G	    /home/matt/snap
4.0K	/home/matt/Templates
4.0K	/home/matt/Untitled Document 1
4.0K	/home/matt/Untitled Document 2
13M	    /home/matt/Videos