Cheatsheet; Free up Linux disk space

Image by bohed from Pixabay

How much is actually free now? df -h

df -hwill give you a simple understanding of how much disk space you’ve got remaining. You can filter out loopback and temporary partitions easily with; dg -h | egrep -v 'tmp|loop'

Filesystem                 Size   Used   Avail   Use%   Mounted On
/dev/mapper/centos-root 100G 60G 40G 60% /
...

How big is that file? — du -h

user@host: du -hs messages
20M messages

Which files are taking up space? — ncdu

You probably need to install the NCurses Disk Usage tool; yum install ncdu (Fedora, CentOS) or apt-get install ncdu (Debian, Ubuntu, etc). It’s awesome though;

Awesome! Better delete those boost libraries, so much bloat!

Useful tip; ncdu -x /mnt/myStuff will make ncdu just stay on the same filesystem (very useful when scanning root — / for example).

Shortcut keys; ? for help, d to delete the currently selected item

/var/log/journal — Delete old logs

Warning: Check if you’re allowed to delete old logs on a production system, if you don’t own that system!

If /var/log/journal is getting too big, you can easily delete old logs;

journalctl --vacuum-size 100M — Deletes all of the older logs until you get down to 100 Mb

...
Deleted archived journal /var/log/journal/9b57750d29bb4165956552cc5e3261b4/user-1000@af904f609b3645d5965a0ad33e1cba01-0000000000020a0e-0005aaa09409d7e6.journal (72.0M).
Deleted archived journal /var/log/journal/9b57750d29bb4165956552cc5e3261b4/user-1000@af904f609b3645d5965a0ad33e1cba01-0000000000040ea9-0005ad04e17c296b.journal (128.0M).
Vacuuming done, freed 3.8G of archived journals from /var/log/journal/9b57750d29bb4165956552cc5e3261b4.
Vacuuming done, freed 0B of archived journals from /var/log/journal.

Or alternatively, you could delete logs based on time;

journalctl --vacuum-time=3d — keep logs only from the last 3 days

/var/cache/yum — Delete cached package downloads (Fedora, CentOS)

yum clean all Will clear out Yum’s cache of previously downloaded packages.

/var/cache/apt/archives/ — Delete cached package downloads (Debian, Ubuntu)

apt-get clean — will clear out Apt’s cache of previously downloaded packages.

apt-get autoclean — will clear out packages that can no longer be downloaded.

Remove unneeded packages

yum autoremove(Fedora, CentOS) or apt-get autoremove(Debian, Ubuntu) — a lot of people don’t know about this one. It removes old dependencies, old kernels, etc.

Image by bohed from Pixabay

--

--

James Read
James Read’s Code, Containers and Cloud blog

Public Cloud and Open Source advocate. Red Hat Solution Architect during the day. Enthusiastic developer at night :) http://jread.com