Running out of disk space can bring down databases, break log writing, and crash applications. This guide covers finding what's consuming your storage and safely reclaiming space.
Checking Overall Disk Usage
df -h
Focus on the Use% column — anything consistently above 85% needs attention.
Finding Which Directories Are Largest
sudo du -h --max-depth=1 / 2>/dev/null | sort -hr | head -15
Then drill into the largest directory:
sudo du -h --max-depth=1 /var 2>/dev/null | sort -hr
Using ncdu for Interactive Exploration (Recommended)
sudo apt install ncdu -y
sudo ncdu /
ncdu lets you navigate directories interactively and see exactly what's consuming space — much faster than repeated du commands.
Common Culprits
Log Files
sudo du -sh /var/log/*
Check journal size specifically:
sudo journalctl --disk-usage
Trim it:
sudo journalctl --vacuum-time=7d
Package Cache
sudo apt clean
sudo apt autoremove -y
Docker (If Installed)
docker system df
docker system prune -a
Old Kernels
dpkg -l | grep linux-image
Remove old, unused kernel versions with apt autoremove (Ubuntu/Debian handle this automatically in most cases).
Finding Large Individual Files
sudo find / -xdev -type f -size +100M -exec ls -lh {} \; 2>/dev/null
Checking Inode Usage (Different from Disk Space)
Sometimes a disk shows free space but you still get "No space left on device" — this means you've run out of inodes (often caused by millions of tiny files, like session or cache files):
df -i
Extending Disk Space
If you've genuinely outgrown your current storage, resizing the VPS plan (via your provider's control panel, usually followed by a filesystem resize) is the correct long-term fix rather than repeated manual cleanup.
Common Errors
"No space left on device" but df shows free space — check inode usage with df -i; you may have hit the inode limit.
Deleted a large file but space wasn't freed — a process may still hold the file open. Find and restart it:
sudo lsof +L1
Best Practices
- Set up log rotation and journal size limits proactively, not reactively
- Monitor disk usage regularly rather than waiting for a failure
- Automate cleanup (old logs, package cache) via cron
FAQ
Is it safe to delete files in /var/log?
Generally yes, for older rotated logs (e.g. *.log.1, *.gz), but avoid deleting the active log file a running service is currently writing to — rotate or truncate it instead.
Related Articles
- How to Check VPS Resource Usage (CPU, RAM & Disk)
- How to Read and Analyze Linux Logs with journalctl
- How to Choose the Right VPS Plan for Your Workload
