Disk full — emergency cleanup and prevention

12.03.2026
Complexity
min.

Summary

If the server ran out of disk space: find large files, clean up logs, temporary files, and set up automatic cleanup.

Applies to:
✔ VPS
✔ Dedicated servers
✔ Linux (Ubuntu, Debian, CentOS)

Diagnostics: how much space is used

Overview by partitions:

df -h

If the root partition / is 95-100% full, you need to free up space immediately.

Finding large files and directories

Find the largest directories:

du -sh /* 2>/dev/null | sort -rh | head -10

Drill into the largest one:

du -sh /var/* 2>/dev/null | sort -rh | head -10

For a convenient interactive view, install ncdu:

apt install ncdu -y
ncdu /

Cleaning up logs

System journal (journald)

Check journal size:

journalctl --disk-usage

Clean entries older than 3 days:

journalctl --vacuum-time=3d

Limit maximum journal size. In /etc/systemd/journald.conf:

SystemMaxUse=200M
systemctl restart systemd-journald

Application logs

Check log sizes in /var/log:

du -sh /var/log/* | sort -rh | head -10

Clear old logs (without deleting the file itself):

truncate -s 0 /var/log/syslog.1

Cleaning temporary files

rm -rf /tmp/*
rm -rf /var/tmp/*

Cleaning package manager cache

Debian/Ubuntu:

apt clean

CentOS/RHEL:

yum clean all

MySQL/MariaDB: binary logs

MySQL binary logs can take up tens of gigabytes:

du -sh /var/lib/mysql/
ls -lh /var/lib/mysql/mysql-bin.*

Remove old binary logs (keep last 3 days):

mysql -e "PURGE BINARY LOGS BEFORE DATE(NOW() - INTERVAL 3 DAY);"

Limit retention in MySQL config (/etc/mysql/my.cnf):

expire_logs_days = 7
max_binlog_size = 100M

Removing old kernels (Ubuntu/Debian)

apt autoremove --purge -y

Prevention: scheduled cleanup

Add a cron job for regular cleanup:

crontab -e

Add a line (clean logs older than 14 days weekly):

0 3 * * 0 find /var/log -name "*.gz" -mtime +14 -delete

Verification

df -h /

Root partition usage should be below 85%.

If space is not freed after cleanup or the disk fills up again within hours, open a support ticket. A disk expansion or investigation into abnormal data growth may be needed.
Was this information helpful?
Yes   No
 
By continuing to use this website you will be agreeing to the website Acceptable Use Policy and the Use of Cookies while using the website and our services. Please also read our Privacy Policy under which, to the extent stated, you consent to the processing of your personal data.