How to Fix Linux Disk Full — No Space Left on Device
In this tutorial, you'll learn about How to Fix Linux Disk Full. We cover key concepts, practical examples, and best practices.
You try to write a file or run a command and get No space left on device — the disk is completely full, preventing any write operations.
The Problem
write error: No space left on device
Or:
Error: ENOSPC: no space left on device, write
Step-by-Step Fix
Step 1: Check disk usage
df -h
Expected:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 50G 0 100% /
Find which partition is full.
Step 2: Find the largest directories
du -sh /* 2>/dev/null | sort -rh | head -10
For the current directory:
du -sh * .[!.]* 2>/dev/null | sort -rh | head -10
Step 3: Clean package manager cache
Debian/Ubuntu:
sudo apt clean
sudo apt autoremove
RHEL/Fedora:
sudo dnf clean all
Step 4: Remove old logs
sudo journalctl --vacuum-time=7d
sudo find /var/log -name "*.log" -mtime +30 -delete
Step 5: Clean Docker data (if installed)
docker system prune -a --volumes
Step 6: Remove old kernels
sudo apt autoremove --purge
Check which kernels are installed:
dpkg --list | grep linux-image
Step 7: Find and remove large files
find / -type f -size +100M -exec ls -lh {} \; 2>/dev/null | sort -k5 -rh | head -20
Step 8: Empty trash and temporary files
rm -rf ~/.local/share/Trash/*
rm -rf /tmp/*
Prevention Tips
- Monitor disk usage with
df -hregularly - Set up log rotation with
logrotate - Use
ncdufor interactive disk analysis - Configure Docker log limits
- Set up disk usage alerts
Common Mistakes with disk full
- Mixing let bindings with <- bindings in do notation, producing type errors
- Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
- Non-exhaustive pattern matches that compile with warnings then crash at runtime
These mistakes appear frequently in real-world LINUX code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro