The No space left on device error appears when a write fails because the disk is 100% full. You need to free space within 10 minutes before the server stalls.
Step 1 — Assess the situation (1 minute)
Bash
# Overall disk usage
df -h
# Example output
# Filesystem Size Used Avail Use% Mounted on
# /dev/sda1 50G 50G 0 100% / ← problemBash
# Also check inode usage (too many files can cause the same error)
df -i
# If inodes are at 100%, you have too many files → see the inode section belowStep 2 — Find the culprit directories (2 minutes)
Bash
# Sort first-level directories under root by size
sudo du -sh /* 2>/dev/null | sort -rh | head -15
# Drill into the large directories
sudo du -sh /var/* 2>/dev/null | sort -rh | head -10
sudo du -sh /var/log/* 2>/dev/null | sort -rh | head -10Common large directories:
| Location | Cause |
|---|---|
/var/log | Log files piling up |
/var/lib/docker | Docker images and containers |
/tmp | Uncleaned temp files |
/home | User files |
/var/cache/apt | Package cache |
Step 3 — Quick cleanup (5 minutes)
Clean up log files
Bash
# journald logs (usually the biggest win)
sudo journalctl --disk-usage
sudo journalctl --vacuum-size=200M # keep only 200MB
sudo journalctl --vacuum-time=7d # keep only the last 7 days
# Find old log files
sudo find /var/log -name "*.log" -mtime +30 -size +10M
# Delete rotated/compressed logs
sudo find /var/log -name "*.gz" -delete
sudo find /var/log -name "*.1" -deleteClean package cache
Bash
# Ubuntu/Debian
sudo apt autoremove -y
sudo apt autoclean
sudo apt clean # delete everything in /var/cache/apt/archives
# CentOS/RHEL
sudo yum clean all
sudo dnf clean allClean Docker
Bash
# Remove unused containers, images, volumes, and networks in one shot
docker system prune -f
# Also prune volumes (watch out for data loss!)
docker system prune -f --volumes
# Prune images only
docker image prune -a -f
# Check usage
docker system dfFind large files
Bash
# Search the whole filesystem for files ≥ 1GB
sudo find / -xdev -size +1G -printf "%s %p
" 2>/dev/null | sort -rn | head -10
# 500MB or larger
sudo find / -xdev -size +500M -printf "%s %p
" 2>/dev/null | sort -rn | head -20Clean /tmp
Bash
# Delete old temp files (older than 7 days)
sudo find /tmp -mtime +7 -delete
sudo find /var/tmp -mtime +30 -deleteStep 4 — Fix inode exhaustion
If you still have free disk space but get the same error, you are out of inodes.
Bash
df -i # Check IUse%
# Find directories with the most files
sudo find / -xdev -printf "%h
" 2>/dev/null | sort | uniq -c | sort -rn | head -10Usual culprits:
- PHP session files:
/var/lib/php/sessions/ - Thumbnail cache:
/var/cache/ - Mail queue:
/var/spool/mail/ - Thousands of tiny files inside Node.js
node_modules
Bash
# Example: clean PHP sessions
sudo find /var/lib/php/sessions -mtime +1 -deletePrevent it from happening again
Bash
# Check logrotate config
cat /etc/logrotate.conf
ls /etc/logrotate.d/
# Monitor disk usage (cron alert)
# Create /etc/cron.daily/disk-alert
cat > /tmp/disk-alert.sh << 'SCRIPT'
#!/bin/bash
THRESHOLD=85
USAGE=$(df / | awk 'NR==2 {print $5}' | tr -d '%')
if [ "$USAGE" -gt "$THRESHOLD" ]; then
echo "Disk usage ${USAGE}%" | mail -s "[ALERT] Low disk space" admin@example.com
fi
SCRIPT
sudo mv /tmp/disk-alert.sh /etc/cron.daily/disk-alert
sudo chmod +x /etc/cron.daily/disk-alertEditorial note
AI tools may assist drafting. Check the evidence in each guide for whether commands were run and which environment was used. Confirm the current docs for your version before applying instructions, and email us about errors. email us
Topic-related official docs (auto-linked · not per-claim sources)Docker documentation ↗Linux man pages ↗
Questions & answers
Ask a question about this guide. We'll review and reply.