Skip to content

How to Fix Linux Disk Full — No Space Left on Device

DodaTech Updated 2026-06-24 2 min read

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 -h regularly
  • Set up log rotation with logrotate
  • Use ncdu for interactive disk analysis
  • Configure Docker log limits
  • Set up disk usage alerts

Common Mistakes with disk full

  1. Mixing let bindings with <- bindings in do notation, producing type errors
  2. Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
  3. 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

### Why does df show free space but I still get no space errors?

The filesystem may be out of inodes (small files consuming all inodes). Check with df -i. If inodes are full, delete many small files. Alternatively, the disk may have reserved blocks (5% for root).

How do I check inode usage?

Run df -i to see inode usage. If inodes are at 100%, delete unnecessary small files. This often happens with mail spools, cache directories, or temp files.

Can I recover space without deleting anything?

Compress old logs with gzip, move files to external storage, resize partitions, or add a new disk and mount it. Use du -sh /var/log/* | sort -rh to find compressible logs.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro