A Linux disk full error rarely announces itself politely. MySQL refuses writes, Nginx cannot write its logs, PHP sessions fail, Git complains that there is no space left on device and a WordPress site shows a blank page. The fix is almost always simple once you know what is using the space, and dangerous if you start deleting files at random. This runbook goes from the filesystem down to single files with standard tools: df to see which mount is full, du and find to locate large directories and files, lsof to find deleted files that still hold space, plus inodes, journal logs, package caches and the ext4 reserved blocks that explain why a disk looks full before it reaches 100 percent. The commands target Ubuntu and Debian VPS servers and work the same on most distributions.

Linux disk full troubleshooting steps: df shows the full filesystem, du and find locate large directories and files, lsof finds deleted open files, then clean logs and caches safely
A Linux disk full runbook: df, du, find and lsof to locate the problem, then safe cleanup of logs, caches and old files.

From my own work: On client servers that suddenly fill up, the cause has usually been one of four things: an application log nobody rotated, backups written to the same disk they were supposed to protect, Docker images and build cache, or a deleted log file that a running process still had open. Checking those four first saves a lot of time.

Step 1: confirm which filesystem is full with df

Start with an overview of every mounted filesystem. The -h flag prints human-readable sizes, and -T adds the filesystem type:

df -hT
# Filesystem     Type   Size  Used Avail Use% Mounted on
# /dev/sda1      ext4    79G   75G     0 100% /
# /dev/sda15     vfat   105M  6.1M   99M   6% /boot/efi
# tmpfs          tmpfs  796M  1.1M  795M   1% /run

Note the mount point that is full. Everything after this step is limited to that one filesystem, because scanning /proc, network mounts or a separate data disk wastes time and gives misleading totals.

Then check inodes. A filesystem can run out of inodes, the entries that describe each file, while plenty of bytes are still free. The error message is the same, No space left on device:

df -i /
# Filesystem      Inodes   IUsed IFree IUse% Mounted on
# /dev/sda1      5242880 5242880     0  100% /

If IUse% is at 100 percent, skip to the inode section below. If bytes are full, continue with step 2.

Step 2: find the largest directories with du

du adds up the space used by files under a directory. The -x option keeps it on one filesystem, so it does not wander into other mounts, and --max-depth=1 (short form -d 1) prints only one level (GNU du manual). Sort the result with sort -h, which understands the K, M and G suffixes:

sudo du -xh --max-depth=1 / 2>/dev/null | sort -h | tail -15
# 1.2G    /usr
# 3.9G    /home
# 61G     /var
# 67G     /

Repeat one level deeper inside the largest directory until you reach the culprit:

sudo du -xh --max-depth=1 /var 2>/dev/null | sort -h | tail -10
sudo du -xh --max-depth=1 /var/log 2>/dev/null | sort -h | tail -10

On a busy server, drilling down three levels takes a minute and almost always ends at one of the usual suspects in the table below. If you prefer an interactive view, sudo apt install ncdu and run sudo ncdu -x /; it shows the same totals and lets you browse with the arrow keys.

Location What grows there Safe first action
/var/log Application, Nginx, PHP and old rotated logs Fix rotation; compress or delete old *.gz files
/var/log/journal systemd journal journalctl --vacuum-size=
/var/lib/docker Images, stopped containers, volumes, build cache, container logs docker system df, then targeted prune
/var/lib/mysql Databases, binary logs Check binlog retention; never delete data files by hand
/var/cache/apt Downloaded packages sudo apt-get clean
/home, /root, /tmp Backups, uploads, database dumps, core files Move backups off the server

Step 3: find large files directly

Sometimes a single huge file is hidden deep in a tree. find can list every file above a size on one filesystem, with its size in bytes, and numfmt turns the numbers into readable units:

sudo find / -xdev -type f -size +200M -printf '%st%pn' 2>/dev/null 
  | sort -n | tail -20 | numfmt --field=1 --to=iec
# 412M    /var/lib/mysql/binlog.000233
# 1.9G    /home/deploy/backup-2026-11-01.tar.gz
# 7.4G    /var/www/site/wp-content/debug.log

If you want both views in one pass, plus a count of entries per directory for the inode case, this standard-library Python script walks one filesystem and prints the largest top-level directories, the largest files and the directories with the most entries. It counts allocated blocks, so sparse files such as VM images are not overstated:

#!/usr/bin/env python3
"""diskhogs.py - biggest files, biggest directories and inode-heavy directories
on ONE filesystem. Standard library only. Usage: sudo python3 diskhogs.py / [top_n]"""
import heapq
import os
import sys
from collections import Counter

def human(n):
    for unit in ("B", "K", "M", "G", "T"):
        if n < 1024:
            return f"{n:.0f}{unit}" if unit == "B" else f"{n:.1f}{unit}"
        n /= 1024
    return f"{n:.1f}P"

def scan(root, top_n=15):
    root_dev = os.lstat(root).st_dev
    files = []                    # min-heap of (size, path)
    dir_bytes = Counter()         # bytes per first-level directory
    dir_inodes = Counter()        # entries per directory (finds "millions of tiny files")
    errors = 0
    for dirpath, dirnames, filenames in os.walk(root, onerror=lambda e: None):
        # do not cross into other mounts (/proc, /sys, Docker overlays, NFS ...)
        keep = []
        for d in dirnames:
            try:
                if os.lstat(os.path.join(dirpath, d)).st_dev == root_dev:
                    keep.append(d)
            except OSError:
                errors += 1
        dirnames[:] = keep
        dir_inodes[dirpath] += len(filenames) + len(dirnames)
        rel = os.path.relpath(dirpath, root)
        top = rel.split(os.sep)[0] if rel != "." else "(files in root)"
        for name in filenames:
            path = os.path.join(dirpath, name)
            try:
                st = os.lstat(path)
            except OSError:
                errors += 1
                continue
            used = st.st_blocks * 512          # real allocation, sparse files count correctly
            dir_bytes[top] += used
            item = (used, path)
            if len(files) < top_n:
                heapq.heappush(files, item)
            elif item > files[0]:
                heapq.heapreplace(files, item)
    return sorted(files, reverse=True), dir_bytes, dir_inodes, errors

if __name__ == "__main__":
    root = sys.argv[1] if len(sys.argv) > 1 else "/"
    n = int(sys.argv[2]) if len(sys.argv) > 2 else 15
    files, dirs, inodes, errors = scan(root, n)
    print(f"== Largest top-level directories under {root}")
    for d, size in dirs.most_common(n):
        print(f"{human(size):>8}  {d}")
    print(f"n== Largest files")
    for size, path in files:
        print(f"{human(size):>8}  {path}")
    print(f"n== Directories with the most entries")
    for d, count in inodes.most_common(5):
        print(f"{count:>8}  {d}")
    if errors:
        print(f"n({errors} paths could not be read; run with sudo for a full picture)")

I tested it on a small tree with a 30 MB log, a 12 MB archive, 2,000 empty cache files and a 1 GB sparse image. The output lists the two real files first, reports the sparse image as using no space, and shows the cache directory with 2,000 entries at the top of the inode list. Run it as sudo python3 diskhogs.py / 20 on the server.

Step 4: df says full but du finds nothing? Deleted files still open

This is the classic puzzle: df reports 100 percent, yet du adds up to far less. On Linux, deleting a file removes its name, but the space is only released when the last process that has the file open closes it. If someone ran rm on a 20 GB log that Nginx, PHP-FPM or a Java service was still writing, the space stays in use and no directory shows it. lsof +L1 lists open files whose link count is below one, which means they have been unlinked (lsof manual):

sudo lsof -nP +L1
# COMMAND   PID   USER  FD  TYPE DEVICE    SIZE/OFF NLINK    NODE NAME
# php-fpm8 1123 www-data 3w  REG  8,1  21474836480     0  262147 /var/www/site/debug.log (deleted)

There are two ways to get the space back:

  • Restart or reload the process that holds the file, for example sudo systemctl restart php8.3-fpm. The file is closed and the space is freed.
  • Truncate it through /proc if a restart is not possible right now. Use the PID and file descriptor number from the lsof output (FD 3w means descriptor 3): sudo truncate -s 0 /proc/1123/fd/3.

To avoid the problem in future, empty a live log instead of deleting it: sudo truncate -s 0 /var/www/site/debug.log keeps the same file, so the writing process continues normally and the space is freed immediately. For rotation, use logrotate’s copytruncate or a reload in postrotate, as shown in logrotate for Nginx and PHP-FPM.

Out of inodes: millions of tiny files

When df -i shows 100 percent, look for directories with huge numbers of entries rather than large sizes. GNU du can count inodes instead of bytes:

sudo du --inodes -x --max-depth=1 / 2>/dev/null | sort -n | tail -10
sudo du --inodes -x --max-depth=1 /var/lib/php 2>/dev/null | sort -n | tail -5

Typical causes are PHP session files that are never garbage collected, cache plugins writing one file per page variant, mail queues full of bounces, and build tools leaving thousands of temporary files. Delete in a controlled way, oldest first, and fix the source; for example, to remove PHP session files older than two days:

sudo find /var/lib/php/sessions -xdev -type f -name 'sess_*' -mtime +2 -delete

Step 5: safe cleanup of logs, journal and caches

systemd journal. Check its size, then remove the oldest archived journal files until the total is under a limit. The vacuum options only remove archived files, not the active one, so the reported usage can stay a little above the target (journalctl: vacuum options):

journalctl --disk-usage
sudo journalctl --vacuum-size=500M        # or --vacuum-time=14d

To make that permanent, set a cap. By default journald may use 10 percent of the filesystem and keeps 15 percent free, each capped at 4 GB (journald.conf manual). On a small VPS a fixed limit is easier to reason about:

# /etc/systemd/journald.conf.d/size.conf
[Journal]
SystemMaxUse=500M

sudo systemctl restart systemd-journald

Package caches and old kernels. Both are safe to clean on Ubuntu and Debian:

sudo apt-get clean                 # removes downloaded .deb files in /var/cache/apt/archives
sudo apt-get autoremove --purge    # removes old kernels and unused dependencies

Docker. Run docker system df to see how much belongs to images, containers, volumes and build cache, and prune by category rather than with a blanket -a --volumes. The safe filters and a weekly timer are in Docker disk cleanup done safely.

Backups on the same disk. A backup stored on the server it protects is lost together with that server and fills its disk. Move archives to object storage and keep only the newest local copy, for example with restic backups to S3 or Google Drive.

Things not to delete: anything in /var/lib/mysql or /var/lib/postgresql by hand (purge binary logs through the database instead), files under /proc, /sys or /dev, and anything in /usr or /boot that a package manager installed.

Why df shows 0 available before 100 percent: ext4 reserved blocks

On ext4, a share of blocks is reserved for the root user so that system daemons can keep working after ordinary users fill the disk. The mke2fs manual gives the default as 5 percent (mke2fs manual: -m option). That is why Avail can be 0 while Use% shows 95 to 100 percent, and why root processes may still write when a web application running as www-data already cannot. Check the current reservation:

sudo tune2fs -l /dev/sda1 | grep -Ei 'block count|reserved block count|block size'

On a large data-only disk you can lower the reservation, for example sudo tune2fs -m 1 /dev/sdb1, to gain space. On the root filesystem, keep it: it is the safety margin that lets you log in and fix things when the disk is full.

Prevent the next Linux disk full outage

Alert well before the disk is full. A minimal cron or systemd timer check is enough on a small server:

#!/bin/sh
# /usr/local/bin/disk-alert.sh - warn when any real filesystem is above 85% (bytes or inodes)
df -P -x tmpfs -x devtmpfs -x squashfs -x overlay | awk 'NR>1 && $5+0 > 85 {print "bytes", $6, $5}'
df -Pi -x tmpfs -x devtmpfs -x squashfs -x overlay | awk 'NR>1 && $5+0 > 85 {print "inodes", $6, $5}'

Run it hourly and send any output by email or to a chat webhook; the scheduling options are compared in systemd timers vs cron. For graphs and alerts with history, a monitoring agent such as the one in Netdata server monitoring on Ubuntu tracks disk usage and its growth rate, which tells you how many days you have left.

Linux disk full checklist

  • df -hT and df -i: which filesystem, bytes or inodes.
  • du -xh --max-depth=1 | sort -h, drilling down from the mount point.
  • find -xdev -type f -size +200M for single large files.
  • lsof -nP +L1 when df and du disagree.
  • Truncate live logs; never rm a file a service is writing.
  • Journal vacuumed and capped with SystemMaxUse.
  • apt-get clean, autoremove --purge, targeted Docker prune.
  • Backups moved off the server.
  • Alerts at 85 percent for bytes and inodes.

Want this done on your own server or site?

I am Saizul Amin, a web developer and technical SEO consultant. I set up and harden VPS servers, migrate WordPress sites, fix indexing problems and build automations. See my portfolio or get in touch.

FAQ

How do I find what is filling my Linux disk?

Run df -h to see which filesystem is full, then sudo du -xh –max-depth=1 on its mount point, sorted with sort -h, and repeat inside the largest directory. Use find with -xdev and -size +200M to list large single files.

Why does df show the disk full but du shows much less?

Usually a deleted file is still open by a running process, so its space is not released. Run sudo lsof -nP +L1 to find it, then restart that process or truncate the file through /proc/PID/fd/N. Other causes are files hidden under a mount point and the ext4 root reservation.

Is it safe to delete files in /var/log?

Old rotated and compressed logs such as *.gz are generally safe to delete. For active logs, truncate them with truncate -s 0 instead of deleting, and use journalctl –vacuum-size for the systemd journal rather than removing journal files by hand.

What does No space left on device mean when df shows free space?

The filesystem has run out of inodes. Check with df -i. Find directories with huge numbers of small files using du –inodes, remove what is no longer needed, such as old session or cache files, and fix whatever creates them.

How much space does ext4 reserve for root?

By default mke2fs reserves 5 percent of blocks for the super-user. You can see the reserved block count with tune2fs -l and change the percentage with tune2fs -m, which is reasonable on large data disks but not recommended on the root filesystem.

Sources

NEW BLOGS. REAL STRATEGIES. REAL RESULTS.

Join our community and receive powerful SEO tips, web optimization guides, and growth strategies as soon as they’re published.

Don’t just read blogs — stay ahead of the competition.

We don’t spam! Read our privacy policy for more info.

Share.

Comments are closed.