Saving space on Linux
While Linux is a whole lot lighter than Windows, there does come a point at which one has to look at reducing the amount of stuff that's on one's hard drive.
Thankfully, there are a number of possible things that we can do on Linux to find and delete large, bulky, and extraneous files, and I thought I'd post about them here.
Firstly, there's the Disk Usage Analyser, or
baobab. It's a graphical interface that shows you what your hard drive looks like:
Personally, I really appreciate the diagram on the right-hand side - it's a wonderfully visual way of displaying hard disk usage. By right clicking on a directory, you can send it to the recycle bin (don't forget to empty the recycle bin later! Recycle bins on Linux are per-user, so you'll need to make sure you empty them all - you can do root's by doing
sudo nautilus and navigating to the recycle bin).
By default the program starts under your current user, so to do it for any directory you'll need to use
If you don't have a GUI (e.g. if you're trying to clear out a server's hard disk), there's always
ncdu. This, unlike the Disk Usage Analyser, isn't installed by default (at least on Ubuntu Server), so you'll need to install it:
sudo apt install ncdu
Then, you can get it to scan a partition:
sudo ncdu -x /
In the above, I'm scanning
/ (the root partition) with
sudo - as not all the files are under my ownership. The
-x ensures that
ncdu doesn't cross partition boundaries and end up scanning something silly like
By using these tools, not only was I able to clear out a bunch of files my systems don't need, but I also discovered that
/var/log/journald was taking up 4GiB (!) on my laptop's disk. 4 GiB! On systems that use
journald is used to store and manage some log files. It's strange, weird, and I'm not sure I like the opaque storage format, but there you go.
Unlike syslog and logrotate though, it doesn't appear to have a limit set on when it should delete logs. This has to be done manually:
# Show journald disk space usage beforehand journalctl --disk-usage sudo nano /etc/systemd/journald.conf # Add "SystemMaxUse=500M" to the bottom sudo systemctl kill --kill-who=main --signal=SIGUSR2 systemd-journald.service sudo systemctl restart systemd-journald.service # Show journald disk space usage afterwards journalctl --disk-usage
(Source: this Unix StackExchange answer)
Found this helpful? Got another great tip to save space on disk? Comment below!