π How to Track Down Excessive Storage Consumption on a Ubuntu linux β
Running out of disk space on your VPS can break critical services like nginx, databases, or PM2 apps. Knowing how to track and fix excessive storage usage is essential for smooth server management.
This guide will walk you through practical steps to identify whatβs eating your storage and how to clean it safely.
1. Check Overall Disk Usage β
First, see which partitions are filling up:
df -h
Example output:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 80G 75G 2.5G 97% /
Usually / is the one you need to investigate.
2. Identify Large Directories β
Check which top-level directories are consuming space:
sudo du -sh /* 2>/dev/null | sort -h
Common suspects include:
/varβ logs, databases, caches/homeβ user files, uploads/usrβ packages and libraries
3. Drill Down Into Culprits β
If /var is large, investigate further:
sudo du -sh /var/* 2>/dev/null | sort -h
Keep drilling down (e.g., /var/log, /var/lib, /var/www) until you find the big offenders.
4. Find Oversized Files β
Locate huge files directly:
sudo find / -type f -size +100M -exec ls -lh {} \; 2>/dev/null | sort -k5 -h
Look for:
- Giant log files (
.log,.json) - Old backups (
.sql,.tar.gz) - Cached packages or builds
5. Inspect Logs β
Logs often grow uncontrollably.
Check log sizes:
sudo du -sh /var/log/* | sort -h
Systemd journal logs:
sudo journalctl --disk-usage
Example issues:
/var/log/suricata/eve.jsonβ IDS logs bloating to tens of GB/var/log/syslogor/var/log/auth.logβ unrotated system logs
6. Check Package Caches β
On Debian/Ubuntu:
sudo du -sh /var/cache/apt
sudo apt-get clean && sudo apt-get autoremove -y
On CentOS/RHEL:
sudo du -sh /var/cache/yum
sudo yum clean all
7. Check Docker (if used) β
Docker images, volumes, and containers can consume huge space:
docker system df
docker system prune -af --volumes
8. Use Interactive Tools β
Install ncdu for an interactive view:
sudo apt-get install ncdu -y # Debian/Ubuntu
sudo yum install ncdu -y # CentOS/RHEL
sudo ncdu /
Navigate with arrow keys to find whatβs using the most space.
9. Prevent Future Problems β
- Enable log rotation (
logrotateorpm2-logrotate) - Configure app logging (reduce verbose logs like Suricataβs
eve.json) - Move backups off the VPS (e.g., S3, external storage)
- Monitor disk usage with tools like
monit,netdata, or simple cron jobs emailingdf -h
Summary β
When your VPS runs out of space:
- Use
df -hto see full partitions - Use
du -shto find large directories - Drill down into logs, caches, and user files
- Identify large files with
find - Clean safely β truncate logs, clear caches, rotate backups
- Prevent it from happening again with log rotation and monitoring