Home/Engineer/Troubleshooting/Linux Disk Full — Fix "No sp…
TroubleshootingBeginnerUbuntuDebianCentOSRHELNo space leftdfdu

Linux Disk Full — Fix "No space left on device" in 10 Minutes

When a "No space left on device" error appears, this guide shows how to find the culprit in 10 minutes with df, du, and find, then safely clean logs, Docker, package caches, and large files.

Contents
  1. Step 1 — Assess the situation (1 minute)
  2. Step 2 — Find the culprit directories (2 minutes)
  3. Step 3 — Quick cleanup (5 minutes)
  4. Step 4 — Fix inode exhaustion
  5. Prevent it from happening again

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% /        ← problem
Bash
# 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 below

Step 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 -10

Common large directories:

LocationCause
/var/logLog files piling up
/var/lib/dockerDocker images and containers
/tmpUncleaned temp files
/homeUser files
/var/cache/aptPackage 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" -delete

Clean 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 all

Clean 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 df

Find 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 -20

Clean /tmp

Bash
# Delete old temp files (older than 7 days)
sudo find /tmp -mtime +7 -delete
sudo find /var/tmp -mtime +30 -delete

Step 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 -10

Usual 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 -delete

Prevent 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-alert
#No space left#df#du#Troubleshooting#Docker
Editorial 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.