How to Fix No Space Left on Device Errors in Linux

By Tech Writer Linux
Complete guide to diagnosing and fixing disk space issues in Linux. Learn how to find large files, clean up logs, and free up space safely.

Understanding No Space Left Errors

The "No space left on device" error occurs when your filesystem runs out of available disk space or inodes. This guide will help you diagnose and fix the issue quickly.

Quick Diagnosis

df -h  # Check disk space
df -i  # Check inode usage
du -h --max-depth=1 / 2>/dev/null | sort -hr | head -20

Common Solutions

Clean Package Cache

sudo apt-get clean
sudo apt-get autoclean
sudo apt-get autoremove

Clear Log Files

sudo journalctl --vacuum-time=3d
sudo find /var/log -name "*.gz" -mtime +30 -delete

Remove Old Kernels

sudo apt-get autoremove --purge

Clean Docker

docker system prune -a --volumes

Find Large Files

sudo find / -type f -size +100M 2>/dev/null | xargs ls -lh

Prevention

  • Set up log rotation in /etc/logrotate.conf
  • Configure journal size limits
  • Monitor disk usage with alerts
  • Schedule cleanup scripts