So you have been running your Ubuntu Server for a while and recently found out that the disk usage is already at 70%!? Then lets free some space up.
This tutorial will help you liberate space on your system without breaking anything in the process.
Before we start
While this tutorial is focused on Ubuntu Server, it can be used for many other distributions that use the same packages, like Ubuntu Desktop, Debian, Linux Mint, etc.
- An Ubuntu server
- Access to your server
Packages are archived and stored, if these versions can't be downloaded anymore --because there is a newer version or any other reason--, they end up being unnecessary. So let's clean lingering packages.
# Find no longer available packages and remove them sudo apt autoclean -y
Chances are that when you update and upgrade your system, some packages end up being unnecessary. But your system won't remove them, so lets tell it to do that.
# Find unnecessary or redundant packages and remove them sudo apt autoremove -y
Application logs keep increasing the disk usage of your server, specially if it is a busy one. But if we don't care much about keeping records, we can just delete them.
# Check current logs disk usage sudo journalctl --disk-usage # Rotate logs so they are saved to disk sudo journalctl --rotate # Clean any log that is older than one second sudo journalctl --vacuum-time=1s # One liner sudo journalctl --rotate && sudo journalctl --vacuum-time=1s
Now we are switching to a more manual approach.
We will be using
ncdu, a very easy-to-use CLI tool that will show us the biggest files on our system.
sudo apt update -y # Install ncdu sudo apt-get install -y ncdu # Show biggest files in the system sudo ncdu /
Now that ncdu has scanned your system you can:
- Select with the arrow keys
- Enter directories with
- Remove directories and files with
Thats how easy it is.
⚠ Be careful not to delete any important file. In case of doubt, don't do it. ⚠
You can now search for more specific guides.
For example, if you are using Docker, you might want to learn how to remove unnecessary resources.
If you have found this useful, then you should follow me, I will be posting more interesting content! 🥰
Or support me financially. 💸
Today you have learned how to free up space on your system by removing packages, logs and files.
Let me know how much space you have recovered in the comments!