A VPS running low on disk space can cause application failures, database corruption, or a complete outage. This guide covers safely identifying and reclaiming disk space without accidentally breaking something important.
Step 1 — Get an Overview of Disk Usage
df -h
Step 2 — Find What's Actually Using Space
sudo du -sh /* 2>/dev/null | sort -rh | head -20
Shows the largest top-level directories, sorted by size — drill into the largest ones progressively to find specific space-consuming culprits.
Step 3 — Check for Oversized Log Files
sudo find / -name "*.log" -size +100M 2>/dev/null -exec ls -lh {} \;
Runaway log files are one of the most common causes of unexpected disk usage — see How to Set Up Log Rotation with logrotate to prevent recurrence after cleaning up.
Step 4 — Clean Up Package Manager Cache
sudo apt clean
sudo apt autoremove
Step 5 — Clean Up Old Kernel Versions
sudo apt autoremove --purge
Removes old kernel versions no longer in use, which can accumulate meaningful disk usage on a system with many past updates.
Step 6 — Check for Large Docker Artifacts
docker system df
docker system prune -a
Caution: -a removes all unused images, not just dangling ones — verify you don't need any currently-stopped-but-intended-to-keep images before running this.
Step 7 — Check for Old Backup Files Left Locally
find / -name "*.bak" -o -name "*.old" 2>/dev/null
Review before deleting — some may be intentional and needed; others may be forgotten leftovers from past manual work.
Step 8 — Check for Core Dumps
find / -name "core.*" -size +10M 2>/dev/null
Core dumps from crashed applications can be surprisingly large and are usually safe to delete once any relevant debugging has been completed.
Step 9 — Check systemd Journal Size
journalctl --disk-usage
sudo journalctl --vacuum-size=500M
Caps the systemd journal to a specific size, removing older entries beyond that limit.
What NOT to Do
- Never delete files in
/procor/sys— these are virtual filesystems, not actual disk-consuming data - Don't blindly delete files just because they're large without understanding what they are
- Don't run broad, unreviewed
rm -rfcommands based on generic disk-cleanup advice without verifying paths are correct for your specific situation
Preventing Future Disk Space Issues
- Set up disk usage monitoring/alerting (see How to Set Up Effective Server Alerting)
- Configure log rotation for all application logs, not just system defaults
- Periodically review and clean up old backups per your retention policy (see Data Retention Policies: What to Keep and What to Delete)
Common Errors
Deleted files but df still shows full disk — a process may still hold an open file handle to a deleted file, keeping the space allocated until that process restarts; identify with lsof | grep deleted and restart the relevant service.
Continue Reading
- How to Check and Manage Disk Usage on a Linux VPS
- How to Set Up Log Rotation with logrotate
- How to Set Up Effective Server Alerting (Without Alert Fatigue)
Browse more articles in Linux Server Administration.