A Linux server can report that a filesystem is almost full even when the visible files do not appear large enough to explain the reported usage. You run df -h and see that the disk is using 90% of its capacity, but du reports significantly less storage consumption.
This situation is confusing, particularly when a server displays errors such as:
No space left on device The difference usually comes from how Linux measures filesystem usage. The df command reports space used and available on an entire filesystem, while du estimates storage consumed by files and directories that it can access.
One of the most common reasons for a large discrepancy is a deleted file that a running process still has open. Other causes include insufficient permissions, exhausted inodes, mounted filesystems, reserved filesystem space, and snapshots.
This guide explains how to diagnose the difference between df and du, identify the actual source of disk usage, and recover storage safely without deleting important application or database files.
The two commands measure different aspects of storage usage.
The df command reports filesystem-level information, including:
For example:
df -h Example output:
Filesystem Size Used Avail Use%
/dev/sda2 50G 42G 5G 90% This indicates that the filesystem has 50 GB of total capacity and approximately 42 GB of reported used space.
The du command estimates the storage used by files and directories.
For example:
sudo du -sh /var Example output:
/var 18G If df reports 42 GB used while du reports only 18 GB for the directory you inspected, the numbers are not necessarily contradictory. You may have checked only one directory, or some allocated filesystem blocks may not be represented by visible files.
The GNU Coreutils documentation explains the separate purposes of df and du.
Before investigating advanced causes, make sure both commands examine the same filesystem.
Start by checking filesystem types and mount points:
df -hT Then inspect the filesystem containing the directory you are investigating:
df -hT /var For a directory-level breakdown, use:
sudo du -x -h --max-depth=1 /var 2>/dev/null | sort -h The options mean:
-x: Stay on the filesystem containing the starting directory.-h: Display human-readable sizes.--max-depth=1: Show immediate subdirectories.sort -h: Sort sizes from smaller to larger.You can investigate the largest directory further:
sudo du -x -h --max-depth=1 /var/log 2>/dev/null | sort -h For a root filesystem investigation, use:
sudo du -x -h --max-depth=1 / 2>/dev/null | sort -h The -x option is important when the system has several mounted filesystems. Without it, du may include directories from other filesystems, making the comparison misleading.
Running du with sudo also helps avoid undercounting directories that the current user cannot access.
A deleted file can continue consuming disk space when a running process still has it open.
This is one of the most important causes of the Linux df and du mismatch.
Consider a web server that writes application messages to a large log file.
An administrator deletes the log:
sudo rm /var/log/application.log The directory entry disappears, but the web server still has an open file descriptor referencing the original file.
Linux does not release the file’s allocated storage until the final open reference is closed.
As a result:
ls no longer displays the file.du cannot count it through the directory tree.df continues reporting the allocated filesystem blocks.This behavior is defined by the Linux unlink() system call. See the unlink(2) manual page.
The lsof utility lists files opened by running processes.
On Debian or Ubuntu:
sudo apt update
sudo apt install lsof On RHEL-compatible distributions:
sudo dnf install lsof Run:
sudo lsof -nP +L1 The +L1 option tells lsof to display open files whose link count is less than one.
Example output:
COMMAND PID USER FD TYPE SIZE/OFF NLINK NAME
nginx 1450 root 5w REG 536870912 0 /var/log/nginx/access.log (deleted) Important columns:
| Column | Meaning |
|---|---|
| COMMAND | Process holding the file open |
| PID | Process identification number |
| FD | File descriptor |
| TYPE | Type of opened object |
| SIZE/OFF | File size or current offset |
| NLINK | Number of remaining hard links |
| NAME | File name or reported path |
In this example, the nginx process still holds a deleted log file that occupies approximately 512 MB.
Pay attention to the filesystem and file type. Not every deleted entry reported by lsof represents ordinary disk consumption; confirm that the entry is a regular file on the affected filesystem.
Use the PID from the output:
ps -fp 1450 You can also inspect the corresponding systemd service if you know its name:
sudo systemctl status nginx Do not assume that every deleted file belongs to a log service. Databases, application servers, and other processes can also hold deleted files open.
Sometimes Linux reports that no space is available even when df -h shows free disk capacity.
This can happen when the filesystem runs out of inodes.
An inode stores metadata about a filesystem object, such as its owner, permissions, timestamps, and references to data blocks.
A filesystem can run out of inodes when it contains an enormous number of small files, even if those files consume relatively little storage.
Run:
df -i Example:
Filesystem Inodes IUsed IFree IUse%
/dev/sda2 3200000 3200000 0 100% The filesystem has exhausted its available inodes.
GNU du supports inode counting:
sudo du --inodes -x --max-depth=1 /var 2>/dev/null | sort -n This can help identify directories containing large numbers of filesystem objects.
Investigate the largest directories before removing anything.
Common sources include:
Do not use broad deletion commands without understanding what creates the files and whether an application depends on them.
A mounted filesystem can hide files that already existed underneath its mount point.
For example, suppose a directory /mnt/storage contains files on the root filesystem. Later, another filesystem is mounted at /mnt/storage.
The mounted filesystem becomes visible through that path, while the original directory contents underneath it are hidden from normal directory traversal.
This can produce a discrepancy when investigating the root filesystem.
Run:
findmnt -R / To identify the filesystem associated with a particular path:
findmnt -T /mnt/storage Review the output alongside:
df -hT Check whether multiple filesystems, bind mounts, or nested mounts affect the directory structure.
Do not unmount a production filesystem simply to inspect the directory underneath it.
Unmounting can interrupt services, applications, databases, and users who depend on that mount.
Plan any deeper investigation during an approved maintenance window and verify which services use the filesystem first.
Some Linux filesystems reserve part of their capacity for privileged system operations.
For example, ext4 filesystems can reserve a percentage of blocks for privileged processes.
This reserve can make the available space for ordinary users lower than expected.
Check the filesystem type:
df -hT / For an ext4 filesystem, inspect its configuration with:
sudo tune2fs -l /dev/sda2 Replace /dev/sda2 with the actual ext4 device identified on your system.
Look for the reserved block count and percentage.
Reserved blocks primarily explain why the Avail column can be lower than expected. They should not automatically be treated as the cause of a large difference in the Used values reported by df and du.
Do not change reserved-block settings on a production filesystem without understanding the operating system’s recovery requirements.
Once you identify the cause, choose a solution appropriate to the affected process and filesystem.
The preferred approach is to make the responsible application close or reopen its old log file.
Depending on the application, this may involve:
For example, after confirming that nginx is holding a deleted log file:
sudo systemctl reload nginx The exact procedure depends on the application and its logging configuration.
Verify the result:
sudo lsof -nP +L1
df -hT /var A successful log reopen should release the old file once no process retains an open reference to it.
Important: Never blindly restart or terminate a process simply because it appears in lsof. Identify the service and its role first. Database files require particular care and must not be treated as ordinary disposable logs.
If applications repeatedly generate large logs, fix the underlying issue rather than repeatedly deleting files.
Possible solutions include:
For Docker environments, see our related guide on Docker Logs Taking Too Much Disk Space once that article is published.
If inode exhaustion is the problem, identify the application generating excessive files.
Use the application’s supported cleanup procedure or retention settings.
Avoid deleting unknown files from directories such as /var/lib, where databases and system services may store important state.
If the storage usage is caused by legitimate application data, repeated cleanup may not solve the underlying capacity problem.
Consider:
For broader storage and filesystem administration, see Linux File System Explained and our Linux Server Administration Complete Guide.
They report different filesystem information. Small differences are normal, and large differences require investigation rather than immediate deletion.
Deleting the directory entry does not necessarily release the storage. Identify the process holding the file and use its supported log-reopen or restart procedure.
A filesystem can have available bytes but no free inodes. Always check df -i when applications report that no space is available.
Use -x when comparing a particular filesystem with df. Otherwise, directory totals may include mounted filesystems.
Never remove files from /var/lib, database directories, or application storage simply because they appear large. Determine what owns the files and whether they are safe to remove.
df reports filesystem-level block usage, while du estimates usage by traversing visible files and directories. Deleted files held open by running processes, mount points, permissions, filesystem metadata, and snapshots can cause differences.
Run:
sudo lsof -nP +L1 Inspect the process, file size, link count, and filesystem. An open regular file with a link count of zero may still consume disk space.
Not always. If a process still has the file open, the filesystem retains its data until the final open reference is closed.
df -h reports filesystem capacity and usage in human-readable units. du -sh estimates the storage used by a specified directory or file tree.
Possible reasons include inode exhaustion, filesystem quotas, reserved blocks, or a full filesystem different from the one you inspected. Check both df -h and df -i, and verify the filesystem used by the affected application.
Yes, when that service is the last process holding the deleted file open. A supported log-reopen or reload operation may be sufficient; otherwise, a controlled restart may be necessary.
When Linux reports more disk usage through df than you can explain with du, the correct response is to investigate the filesystem rather than immediately delete more files.
Start by comparing the same mount point, then check for deleted files still held open with lsof, inode exhaustion with df -i, and unexpected mounted directories with findmnt.
Once the actual cause is identified, use the application’s supported cleanup or log-management procedure and verify the result with df.
Understanding how Linux manages file descriptors, inodes, and filesystem blocks makes disk-space troubleshooting safer and more predictable.
Introduction Border Gateway Protocol (BGP) is the routing protocol used to exchange network reachability information…
Introduction A Linux server can experience connection failures even when its network interface is working…
Introduction TCP retransmissions are an important indicator of network reliability and performance. When a Linux…
Open Shortest Path First (OSPF) is a link-state routing protocol widely used in enterprise networks…
Group Policy is one of the most important management features in Windows Server Active Directory…
Windows DNS servers play an essential role in Active Directory environments, allowing computers, servers, applications,…