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)
Overview by partitions:
df -h
If the root partition / is 95-100% full, you need to free up space immediately.
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 /
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
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
rm -rf /tmp/*
rm -rf /var/tmp/*
Debian/Ubuntu:
apt clean
CentOS/RHEL:
yum clean all
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
apt autoremove --purge -y
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
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.