The fastest way to clean up disk space on server

Today, 4th December 2022, Ukraine is still bravely fighting for democratic values, human rights and peace in whole world. Russians ruthlessly kill all civilians in Ukraine including childs and destroy their cities. We are uniting against Putin’s invasion and violence, in support of the people in Ukraine. You can help by donating to Ukrainian's army.

Your production crashed because "no space left on device" and you have no guess what to delete fast? Do not worry! Here I will show you largest useless points of data and how to find and kill them.

☝ Save the post for future, it happens!

Install ncdu to check who uses space:

apt install ncdu
🤔 Yes, you will need ~100kB of free space to install ncdu: just find some trash in your home directory

Run it:

ncdu /

I suggest you not spend time now, and enter /var/log folder instantly:

Use ncdu to find largest folders and files

In most cases it is systemd's journal folder and btmp file.

Trim current large journal immediately:

journalctl --vacuum-size=50M
😣 So, after several months of work our CI server had 3.6 GB of useless for us data created by OS default tools. Now it is empty.

Also let's force to trim it automatically when journal will exceed 50 M. To limit max used space for journal, open a config file:

 nano /etc/systemd/journald.conf

And add SystemMaxUse under [Journal] section:

🛌 Sleep better after doing it

Fix large btmp file in /var/log/

This file most time contains logs of unsuccessful brute-force attempts. To remove file content on one time basis:

echo '' > /var/log/btmp

To fix it in future:

Are you using docker?

One of the largest points of useless data.

Remove most of useless docker data:

docker system prune -f

Also you might want to remove unused images:

docker rmi $(docker images -f "dangling=true" -q)
👋 Stay clean and have a fun
#ops #devops #disk-space-optimization #cron
Ivan Borshchov profile picture
Apr 13, 2021
by Ivan Borshchov
Did it help you?
Yes !

Best related