A full disk can bring a server to its knees: SSH sometimes refuses connections, and databases stop. This guide shows how to monitor space and inodes with df, find what takes up the space with du and ncdu, unblock the trap of the deleted file that is still open, and reclaim space without breaking the system, starting with what the system can recreate: logs, caches, old kernels. For beginner to intermediate administrators. Each output names, in its title, the machine it was captured on.
What you will learn
- Monitor space and inodes with
df - Find the largest directories with
duandncdu, and large files withfind - Unblock a deleted file that is still open
- Understand ext4 reserved blocks and keep the systemd journal in check
- Reclaim space safely, in the right order
See free space with df
df (disk free) summarizes the usage of each mounted file system. The -h option makes sizes readable, -T adds the type, and excluding tmpfs removes the noise of virtual file systems:
df -hT -x tmpfs -x devtmpfsFilesystem Type Size Used Avail Use% Mounted on/dev/sdb2 ext4 20G 1.2G 19G 6% //dev/sdb1 vfat 99M 8.8M 90M 9% /boot/efiThe Use% column spots at a glance the volumes close to saturation. It is the first command to run when a "disk full" alert comes in.
Read the df columns
Each column answers a precise question. The one that surprises is Avail: it is not always Size - Used, because df subtracts the blocks reserved for root on ext4, explained further down.
| Column | Meaning |
|---|---|
Size | Total size of the file system |
Used | Space in use |
Avail | Space actually available, reserved blocks excluded |
Use% | Percentage in use |
Mounted on | Mount point |
Target a mount point
df reasons per mount point: a server can have / at 40% and /var at 100%, and only checking /, /var, /tmp and /home separately shows it. When you pass a path, df displays only the file system that contains it. If df -h /var returns the same line as df -h /, /var is not on a separate partition.
df -h /vardf -h /tmpMonitor usage in a script
For an automated alert, extract the single useful value. NR==2 skips the header line and $5 designates the Use% column.
usage=$(df -h / | awk 'NR==2 {gsub(/%/,""); print $5}')if [[ "$usage" -gt 90 ]]; then echo "ALERT: / is at ${usage}%"fiThe script only checks /: if /var is a separate partition, add it to the check, otherwise saturation goes unnoticed.
Watch inodes: the trap of the "full" disk
A file system can show free space and still refuse to write: it has run out of inodes, the structures that describe each file. Their number is fixed at creation of the file system. Millions of small files (PHP sessions, caches, mail) can exhaust them well before the space. Check with df -i:
df -i -x tmpfs -x devtmpfsFilesystem Inodes IUsed IFree IUse% Mounted on/dev/sdb2 2557440 36172 2521268 2% /If IUse% is at 100% while df -h shows space, the culprit is an inode shortage, not a lack of space. The fix is to delete the small files involved (or to recreate the file system with more inodes).
When to suspect inode exhaustion
The No space left on device message is the same when the space is full and when the inodes are exhausted. Three signals point to inodes.
df -hshows free space, buttouch /tmp/testanswersNo space left on device. This signal points to inodes, provideddf -hwas read on the same mount point where the write fails (df -h /tmpin this example).- A directory contains millions of small files: cache, PHP sessions, queued mail.
IUse%exceeds 90% indf -i.
Find the directories that hold the most files
There is no equivalent of du for inodes: you have to count files directory by directory. The command ranks directories by number of direct files. It is slow on a big disk, and -xdev at least limits the walk to the current file system.
sudo find / -xdev -type d -exec sh -c 'echo "$(find "$1" -maxdepth 1 -type f | wc -l) $1"' _ {} \; 2>/dev/null | sort -rn | head -10Read the first column: it is the number of files in the directory. The first lines point to the folder to empty or to rotate (rotation, cache purge).
Find what takes up the space with du
df says how much; du (disk usage) says where. To find the big items of a directory, list the first level and sort:
du -h --max-depth=1 /usr | sort -h38M /usr/sbin64M /usr/bin169M /usr/lib64241M /usr/share505M /usr/lib1022M /usrThe sort -h sort (human-numeric) puts the biggest at the bottom, immediately visible. For the total of a folder alone, du -sh /var. Going down from directory to directory, you trace back to the source of the growth.
Start with the overall breakdown
On a machine you are discovering, start with a command whose output fits in about ten lines and points to the branch to explore. sudo avoids missing the directories your account cannot read, and 2>/dev/null keeps the output usable.
sudo du -sh /* 2>/dev/null | sort -rhTo rank the ten biggest items under /, files included, -a adds files and -x stops du from crossing into other mounted file systems. The sort -rh sort understands the G, M and K suffixes, and the first line is always the total of the starting point.
sudo du -ahx / 2>/dev/null | sort -rh | head -10188G /166G /home87G /home/bob/Projets35G /home/bob/.cache29G /home/bob/Projets/labOnce you have found the branch, du -sh on its content goes down one level:
sudo du -sh /var/log/* 2>/dev/null | sort -rh | head -5633M /var/log/journal13M /var/log/pods13M /var/log/crowdsec_api.log2.5M /var/log/harbor1.5M /var/log/libvirtDo not compare the total of a du with the Size of a df taken on another machine: the gap between df and du can only be read on one and the same machine, and it is handled with the deleted files that are still open, further down.
Explore interactively with ncdu
For a faster diagnosis, ncdu (NCurses Disk Usage) combines du and a navigable interface: sorted sizes, arrow-key navigation, deletion with the d key.
sudo apt install ncdusudo dnf install ncdusudo ncdu /varInteractive exploration saves precious time on a server under alert: you go down visually to the faulty folder instead of chaining du commands.
Find large files with find
du points to directories, find points to files. The switch is useful when a single file explains the saturation: a forgotten disk image, a database dump, a log that was never rotated. Three criteria cover most searches: size (-size), modification date (-mtime) and last access date (-atime).
Files over 100 MB
-xdev stops find from descending into other mounted file systems, which avoids walking a network share or a backup disk. The sort uses the fifth column of ls -lh, the size column.
sudo find / -xdev -type f -size +100M -exec ls -lh {} \; 2>/dev/null | sort -k5 -rh | head -10Large files modified recently
Crossing size and freshness answers the question "what is growing right now?". The sign of -mtime reverses the meaning: -7 means the last 7 days, +7 means older than that.
sudo find /var -xdev -type f -size +10M -mtime -7 -exec ls -lh {} \; 2>/dev/nullThe command lists files over 10 MB modified within the week under /var, useful to find a log that grows fast.
Old temporary files
-atime relies on the last access date, which says more than the modification date about what is no longer used. That date is not reliable if the file system is mounted with noatime, common on servers to save writes: in that case -atime proves nothing and you have to fall back on -mtime.
Always start with a preview using -print. -xdev keeps find on the file system of /tmp, without following a mount point placed below it.
find /tmp -xdev -type f -atime +30 -printRead the list. If it only contains files you can do without, run the same command again, replacing -print with -delete. The deletion is irreversible.
The trap of the deleted file still open
A classic and puzzling symptom: you delete a big file, but df still shows the disk full. The cause: a process keeps the file open. As long as it runs, the space is not freed, even though the file has disappeared from the tree. Find these files:
sudo lsof +L1The last column lists the (deleted) files still open, with the process and its PID. The typical case is an application log deleted without reloading the service that writes it. The kernel keeps the blocks as long as a descriptor remains open on the file: du no longer sees anything, df shows the file system full.
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NLINK NODE NAMEnginx 1234 www 4w REG 253,0 2.1G 0 131074 /var/log/nginx/access.log (deleted)Look at the NAME column for the file, PID for the process to deal with, and FD for the descriptor number (here 4), which you will need to empty it. As soon as the last descriptor closes or the file is truncated, df -h reflects the reclaimed space.
Do not pass a mount point as an argument: contrary to what you would expect, it filters nothing. Measured on AlmaLinux 10, lsof +L1 alone returns 9 lines, lsof +L1 /tmp returns 17, and lsof +L1 / returns 1381. The argument selects processes, all of whose entries are then listed, libraries from other file systems included. To narrow down, filter the output:
sudo lsof +L1 | grep '/var/log'Three ways out, in order of preference:
-
Empty the file through its descriptor, without stopping the process. It is often the only acceptable option in production:
Terminal window sudo ls -l /proc/<PID>/fd | grep '(deleted)'sudo sh -c ': > /proc/<PID>/fd/<FD>'The space is given back immediately, the service keeps running and writing to its descriptor.
-
Cleanly restart the service involved with
systemctl restart. The restart interrupts the service, even briefly: check its impact before doing it in production. -
Kill the process, as a last resort. Prefer a normal termination signal to
kill -9, which gives the service no chance to close its files cleanly.
The deleted file is not the only cause of a disk that fills up for no visible reason. On a machine managed by systemd, the journal also grows continuously, in /var/log/journal, and it is purged with its own commands rather than with an rm that could corrupt it.
Contain the systemd journals
The systemd journals grow over time and can take up several hundred MB. They are measured and purged with journalctl, never with rm. Before purging, check that no ongoing investigation needs these logs: the purge is final.
journalctl --disk-usageArchived and active journals take up 632.5M in the file system.Two commands reduce this size: the first limits the volume, the second the age.
sudo journalctl --vacuum-size=200M # keep at most 200 MBsudo journalctl --vacuum-time=7d # or keep only the last 7 daysA one-off purge is not enough if the journal grows back. To make the limit persistent, set SystemMaxUse in /etc/systemd/journald.conf, then restart systemd-journald and check with journalctl --disk-usage.
[Journal]SystemMaxUse=200Msudo systemctl restart systemd-journaldUnderstand ext4 reserved blocks
On ext4, 5% of the space is reserved for root by default. This reserve explains the gap between Size, Used and Avail in df, and it lets root keep writing (system logs, critical processes) when a normal user gets No space left on device. The number of reserved blocks is read with tune2fs -l, filtering on reserved:
sudo tune2fs -l /dev/mapper/ubuntu--vg-ubuntu--lv | grep -i reservedReserved block count: 10002749Reserved blocks uid: 0 (user root)Reserved blocks gid: 0 (group root)The reserved block count is the first line; the next two say the reserve belongs to root (UID and GID 0).
Reduce the reserve on a data volume
On a pure data volume, which does not hold /, the 5% reserve is often too generous. tune2fs -m sets the reserved percentage:
sudo tune2fs -m 1 /dev/mapper/data-lvThis command brings the reserve down from 5% to 1%. Do not do it on /: system processes need that margin to keep writing when the disk is nearly full.
Free up space in the right order
On a running server, the order of operations matters as much as the commands. You diagnose before deleting, you start with the targets whose loss does not break the system (caches, old logs, orphaned packages), and you only touch application data as a last resort.
-
Diagnose: space or inodes?
Terminal window df -h /df -i / -
Locate the directories that consume the most:
Terminal window sudo du -sh /var/* /tmp/* /home/* 2>/dev/null | sort -rh | head -10 -
Look for deleted files that are still open:
Terminal window sudo lsof +L1 -
Clean the targets whose loss does not break the system:
Terminal window # Old journalssudo journalctl --vacuum-time=7d# Package cachesudo apt clean # Debian/Ubuntusudo dnf clean all # RHEL/Fedora# Old temporary files: preview first, delete afterwardsfind /tmp -xdev -type f -atime +30 -printsudo find /tmp -xdev -type f -atime +30 -delete# Orphaned packages and old kernelssudo apt autoremove --purge # Debian/Ubuntusudo dnf autoremove # RHEL/Fedora -
Check the result:
Terminal window df -h /
On Debian and Ubuntu, apt autoremove --purge removes orphaned packages, with their configuration files, and the old kernels that are no longer needed. On RHEL, dnf autoremove removes orphaned dependencies, and the number of kernels kept is set with installonly_limit in /etc/dnf/dnf.conf (the dnf guide gives the example installonly_limit=3). The details are in the dnf guide and the apt guide.
For an application log in /var/log that a service is still writing, do not delete it, or you fall back into the trap of the deleted file still open. Empty it instead with truncate -s 0 /var/log/file.log, which frees the space without touching the service's descriptor.
Reclaim space for good
When cleaning is no longer enough, you have to grow the volume. The approach depends on the underlying layer, detailed in the dedicated guides:
- LVM volume:
lvextend -rgrows volume and file system online (see LVM). - ext4 partition: grow the partition then
resize2fs. - XFS partition: grow then
xfs_growfs(an XFS is not shrunk in practice: shrinking is still experimental).
To limit consumption per user or group upstream, set up disk quotas, covered in the quotas guide.
Troubleshooting
A full disk almost always has one of the causes below, and each one is confirmed by a command before any deletion. Start with df -h and df -i, which already tell a lack of space from a lack of inodes.
| Symptom | Likely cause | Fix |
|---|---|---|
Disk "full" but df -h shows space | inodes exhausted | df -i, delete the small files involved |
| Space not freed after deletion | deleted file still open | lsof +L1, then empty via /proc/<PID>/fd/<FD> or restart the service |
lsof +L1 <mount-point> returns more lines than lsof +L1 alone | The argument selects processes, not a file system | Filter the output with grep, the argument narrows nothing |
| Service restarted, space still not given back | The descriptor is inherited by child processes | lsof +L1 lists parent and children with the same inode: killing the parent alone is not enough |
df says 100% but root still writes | ext4 reserve of 5% kept for root | tune2fs -l <dev> | grep -i reserved; tune2fs -m 1 to lower it |
du -sh clearly underestimates the space used | Unreadable directories, errors swallowed | Run again with sudo; without it, the Permission denied go by silently |
/ fills up for no visible reason | systemd journals or application logs | journalctl --vacuum-size, check /var/log |
/boot full after updates | old kernels piled up | apt autoremove --purge (Debian/Ubuntu); dnf autoremove and installonly_limit in /etc/dnf/dnf.conf (RHEL) |
| The alert script does not detect the saturation | wrong mount point checked | check /var, /tmp and /home separately with df -h <path> |
Avail smaller than Size - Used | blocks reserved for root (5% by default on ext4) | normal; lower with tune2fs -m only on a data volume |
/var fills up very fast | logs not rotated or systemd journal without a limit | configure logrotate and SystemMaxUse in journald.conf |
| Partition full after container builds | images and layers not cleaned up | docker system prune or podman system prune, see Docker logs and disk space |
Put it into practice
Facing a real full disk, theory is no longer enough: you must find the culprit fast and without breaking legitimate data. The lab confronts you with a saturated file system that you diagnose with df and du, before deleting the stray files and bringing usage back under the alert threshold.
Key points
df -hshows space;df -ishows the inodes (a disk can be "full" without lacking space).du -h --max-depth=1 | sort -hfinds the big directories;ncduexplores interactively.- A deleted file still open does not free space:
lsof +L1, then empty it via/proc/<PID>/fd/<FD>or restart the service. - The systemd journals are purged with
journalctl --vacuum-size/--vacuum-time, andSystemMaxUseinjournald.confmakes the limit persistent. - ext4 reserved blocks (5% by default) explain the gap between
Size,UsedandAvail;tune2fs -mlowers them on a data volume, never on/. find /tmp -xdev -atime +30is tried with-printbefore-delete, andatimeis not reliable withnoatime.- You free up space in this order: diagnosis, location, deleted files still open, then the targets whose loss does not break the system.
- To grow for good:
lvextend -r(LVM),resize2fs(ext4) orxfs_growfs(XFS). - Quotas limit consumption per user upstream.
Knowledge check
Check that the essentials of this guide are acquired. The questions only cover what has just been explained here.
Knowledge check
Check what you have learned with this interactive quiz
How it works
- The timer starts when you click Start
- Multiple choice, true/false and short answer questions
- You can move between questions
- Detailed results are shown at the end
Starts the quiz and the timer
Review
(0/0)Result saved on this device. It will be sent to your account at the next sync. Sync now
Score by domain
A domain groups several guides and gets several questions, so its score is more reliable than a per-topic score, which often rests on a single question.
Summary
Strengths
No topic passed at 80% on at least two questions yet.
Weak areas
No topic below the pass mark.
Recommended next
Hints before you try again?
Continue the course: Use NFS on Linux
A new full quiz with random questions
Work again only on the questions you missed