A 300 MB log file was deleted. du agreed it was gone, reporting 20 KB for the whole filesystem. df still showed 301 MB used, and it kept showing that until a single process that had the file open was stopped. The two commands measure different things, and every gap between them points at something real on the disk. The examples below were run on a 1 GB ext4 filesystem created in a test environment, so each number shown is what the tools actually printed.
Two tools, two questions
df asks the filesystem
The df manual page describes it as reporting file system space usage. It asks the filesystem itself how many blocks are in use and how many are free. It never looks at a single file. That makes it fast and authoritative about the disk as a whole, and blind to which files are responsible.
du walks the files
The du manual page calls it a tool to estimate file space usage. It walks a directory tree, asks how much space each file it can find occupies, and adds them up. That makes it slow on big trees and exact about the files it can reach, and blind to anything it can’t reach.
The fresh filesystem
The new 1 GB filesystem, empty:
$ df -h mnt
Filesystem Size Used Avail Use% Mounted on
/dev/loop0 974M 24K 907M 1% /tmp/p14/mnt
$ du -sh mnt
20K mnt
Already two puzzles: the 1 GB disk shows 974M of size, and 974M minus 24K of use leaves far more than the 907M listed as available. Both have explanations, and they are the same explanations behind most real-world mismatches.

Deleted files that are still open
The test
A 300 MB file was written to the disk, and a Python process opened it for reading. Then the file was deleted with rm while the process still held it:
after rm while open:
/dev/loop0 974M 301M 607M 34% /tmp/p14/mnt
20K mnt
du found nothing, because there was no longer a name in any directory for it to walk to. df still counted all 301 MB, because the blocks were still allocated.
Why the space stays used
The unlink manual page explains it: when the last name of a file is removed but a process still has it open, the file remains in existence until the last file descriptor referring to it is closed. Deleting removes the name, not the data. As soon as the test process exited, df dropped back to 24K used.
Finding the culprit
The lsof manual page documents +L1 as selecting open files that have been unlinked. On the test system:
$ lsof -nP +L1
python3 1339 root 3r REG 7,0 314572800 0 12 /tmp/p14/mnt/big.log (deleted)
The link count column reads 0 and the name carries (deleted). The same information sits in /proc: ls -l /proc/1339/fd showed 3 -> /tmp/p14/mnt/big.log (deleted).
This is the classic “disk full but du says it isn’t” case: a log file deleted by hand while the program writing it is still running. Restarting that program, or telling it to reopen its log, releases the space. Truncating a log in place with : > file instead of deleting it avoids the problem entirely.
Containers and log rotation
The same trap shows up in two places people rarely suspect. Log rotation tools that rename and delete old logs without signaling the program writing them leave that program writing into a deleted file, so the rotated log never frees its space and the “new” log stays empty. Containers add another layer: a process inside a container can hold a deleted file open on the host’s disk, and lsof run on the host will list it under the container’s process. In both cases the fix is the same, ending or signaling the process that holds the file, and the clue is the same, a (deleted) entry that refuses to go away.
Reserved blocks and the missing gigabyte
5 percent for root
The gap between Size minus Used and Avail is deliberate. The tune2fs manual page explains that ext filesystems reserve a percentage of blocks that only privileged processes may use, to avoid fragmentation and to let system daemons such as syslog keep working after ordinary users can no longer write. It says the default is normally 5 percent.
The test filesystem confirmed it:
$ tune2fs -l disk.img | grep -E "Block count|Reserved block count|Block size"
Block count: 262144
Reserved block count: 13107
Block size: 4096
13,107 is 5 percent of 262,144, and at 4 KB per block that is about 51 MB held back. On a 4 TB data drive, the same default sets aside about 200 GB.
Changing it on data disks
On a disk that holds only bulk data, with no system services writing to it, the reserve can be lowered with tune2fs -m 1 /dev/sdX1 (1 percent) or similar. On the root filesystem, the reserve is what lets the system still log in and clean up when a user fills the disk, so it is worth keeping.
Why Size isn’t 1 GB
The remainder of the gap comes from the filesystem’s own structures, such as its journal and inode tables, which take space before any file exists and are left out of df’s Size figure. The image was exactly 1 GiB; df reported 974M.

Files du counts differently
Sparse files: big on paper, empty on disk
truncate -s 500M created a 500 MB file without writing any data:
$ ls -lh sparse.img → 500M
$ du -h sparse.img → 0
$ du -h --apparent-size → 500M
$ df → still 24K used
ls and du --apparent-size report the file’s length. Plain du reports the blocks actually allocated, which for an unwritten sparse file is none. The du manual page notes that the apparent size is usually smaller than device usage but can be larger, exactly this case. Virtual machine disk images and some database files are often sparse, which is why copying them carelessly can suddenly fill a disk.
Small files: rounded up to blocks
A directory of 1,000 files, each holding one byte:
$ du -sh small → 4.0M
$ du -sh --apparent-size → 1000
1,000 bytes of data used 4 MB of disk, because every file occupies at least one 4 KB block. Folders full of tiny files, such as source trees, caches and mail directories, use much more disk than their content suggests.
Hard links: counted once
A 50 MB file was given a second name with ln. Asked about both names at once, du -sh a.bin b.bin printed only a.bin, at 50M, and the total was 50M. Asked about each name separately, each showed 50M. du counts each underlying file once per run; the manual page’s -l option changes that and counts every link. Backup tools that use hard links for snapshots rely on this behavior to make disk usage reports add up.
Files hiding under a mount point
The test
100 MB of data was written into a folder, then a separate filesystem was mounted on top of that folder:
$ du -sh hid → 101M (before mounting)
$ du -sh hid → 20K (after mounting)
The 100 MB was still on the parent disk, still counted by its df, but invisible to du and ls, which now saw the newly mounted filesystem instead.
How it happens
This usually happens when a service writes to a folder before the disk meant for it is mounted, for example at boot, or while a network share is temporarily down. Later the mount covers the files and they become unreachable through normal paths.
Finding them
A bind mount of the parent filesystem shows what lies underneath:
mount --bind / /mnt/rootview
du -sh /mnt/rootview/path/to/mountpoint
In the test, the bind-mounted view showed the hidden 101M under the mount point. Unmounting the overlying filesystem would reveal it too, when that is possible.

A troubleshooting order
When df says full and du disagrees
- Check for deleted open files:
lsof -nP +L1. - Remember the reserve: on ext4, Avail is about 5 percent lower than Size minus Used.
- Look under mount points with a bind mount of the parent filesystem.
- Run du as root, since an ordinary user’s du silently skips folders it can’t read.
- Check inodes too, with
df -i, since a disk can run out of file slots before it runs out of space.
When du says big and df disagrees
That direction usually means sparse files or du --apparent-size in use, or du crossing into other mounted filesystems. Adding -x keeps du on one filesystem, so a backup drive mounted under /mnt doesn’t inflate the count for /.
Which number to trust
For “is the disk full?”, trust df. It is the filesystem’s own accounting and the number that decides whether the next write succeeds. For “what is using the space?”, use du, and treat any gap between the two as a lead rather than an error. In every case tested here, the gap was a real thing with a cause: a held-open file, a reserve, a mount, or a block size. Neither tool was lying. They were answering different questions about the same disk.
Sources
- df(1), Linux manual page: https://man7.org/linux/man-pages/man1/df.1.html
- du(1), Linux manual page: https://man7.org/linux/man-pages/man1/du.1.html
- unlink(2), Linux manual page: https://man7.org/linux/man-pages/man2/unlink.2.html
- lsof(8), Linux manual page: https://man7.org/linux/man-pages/man8/lsof.8.html
- tune2fs(8), Linux manual page: https://man7.org/linux/man-pages/man8/tune2fs.8.html
