Installation | Topics | Beyond Lino

Monitoring disk usage

These are just my personal notes. No warranty whatsoever.

Built-in diagnose

Manually see the overall disk usage:

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/simfs       15G  7.0G  8.1G  47% /
tmpfs           205M  2.1M  203M   2% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           820M     0  820M   0% /run/shm

Show all directories that have more than a GB:

$ sudo du / -h | grep '[0-9\.]\+G'

Show all subdirectories and their size (sorted by size):

$ du -h -d1 | sort -h

The -s or --summarize option means “only the specified directories, no subdirs”:

$ du -sh ~/*

Show the ten biggest files:

$  find /home -type f -size +100M -printf '%s %p\n' | sort -nr | head -10

Show the ten biggest directories:

$ du -Sh | sort -rh | head -10

Thanks to Tracking down where disk space has gone and How To Find Large Files and Directories in Unix and Comment rechercher les fichiers et dossiers volumineux sous Linux? for hints.

Automated diagnose

Install monit (sudo apt-get install monit ) and get alerts per email. In /etc/monit/monitrc you can write for example:

check filesystem datafs with path /
   if space usage > 80% for 5 times within 15 cycles then alert
   if space usage > 99% then stop

Visual tools

Baobab:

$ sudo apt install baobab
$ baobab

Duc:

$ sudo apt install duc
$ duc index /usr
$ duc gui /usr

How much disk space does each database use?

MySQL:

$ sudo du -h /var/lib/mysql/

How to clean up some system files

See how much space is taken by the systemd journal:

$ sudo journalctl --disk-usage

Keep only the last 2 weeks of system log files:

$ sudo journalctl --vacuum-time=2weeks

Clean up the cache of the package manager:

$ sudo apt-get clean

Remove packages that were automatically installed to satisfy dependencies for some package and that are no more needed:

$ sudo apt-get autoremove

See which kernel versions are installed:

$ dpkg --get-selections | grep linux-image

Remove an unused kernel image:

$ sudo apt-get remove --purge linux-image-X.X.XX-XX-generic