Table of Contents
Running out of disk space on a VPS causes service failures, database crashes, and package installation errors. Finding the exact files and directories consuming space is the fastest way to fix it.
Step 1: Check Overall Disk Usage
Start by checking disk usage across all mounted filesystems.
df -h
Look for partitions that are close to 100% usage.
Step 2: Identify Large Directories
Use du to find directories consuming the most space.
sudo du -h --max-depth=1 / | sort -hr
This shows top-level directories by size.
Step 3: Drill Down into a Specific Directory
Once you identify a large directory, inspect it further.
sudo du -h --max-depth=1 /var | sort -hr
Common problem areas include /var/log, /var/lib, and /home.
Step 4: Find Large Files
Locate individual files consuming excessive space.
sudo find / -type f -size +1G 2>/dev/null
This lists files larger than 1GB.
Step 5: Check Log File Growth
Logs often grow silently and fill disks.
sudo ls -lh /var/log
sudo du -h /var/log | sort -hr | head
Rotate or clean logs if necessary.
Step 6: Check Docker Disk Usage
Docker is a common source of disk exhaustion.
docker system df
Unused images, volumes, and containers should be cleaned regularly.
Step 7: Clean Package Cache
Old package files can consume significant space.
sudo apt clean
sudo apt autoremove -y
This safely removes unused packages and cache.
You may also want to review this related article: Check and Reduce High Memory (RAM) Usage on Linux
Optional Step: Monitor Disk Usage Continuously
Prevent future disk issues with monitoring.
watch -n 5 df -h