What df actually reports
One line per mounted filesystem, with the size, how much is used, how much
is free, the percentage, and where it's mounted. No arguments means all of
them, which on a modern box includes pseudo filesystems you don't care
about.
$ df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 13G 3.0M 13G 1% /run
efivarfs 256K 23K 234K 9% /sys/firmware/efi/efivars
/dev/nvme0n1p2 3.6T 157G 3.3T 5% /
tmpfs 61G 0 61G 0% /dev/shm
tmpfs 5.0M 8.0K 5.0M 1% /run/lock
Three of those five lines aren't disks. tmpfs is memory
presented as a filesystem, and efivarfs is firmware variables.
The one that matters here is the third, the real volume mounted at
/, with 157 gigabytes used out of 3.6 terabytes. Everything
else is noise unless you're debugging something specific.
Ask about one path
Give df a path and it answers for the filesystem that path
lives on. That's the version to use when you know where the problem is.
$ df -h /var/log
Filesystem Size Used Avail Use% Mounted on
/dev/nvme0n1p2 3.6T 157G 3.3T 5% /
Note that it reports the mount point, not the path. /var/log
isn't its own filesystem here, so the answer is the root volume. If you want
that to change, the path has to be a mount point, which is why
/var/log being its own volume is a common and good idea.
Add a total across filesystems
When you want one line instead of six, --total sums everything in the list, memory filesystems included, so leave them out when you want a number that means disk.
$ df -h --total | tail -1
total 3.7T 157G 3.4T 5% -
The total is bigger than the root filesystem
because the memory filesystems in the list are counted as well, and the
mount column says - because a sum has no mount point. Good for
a rough impression, useless for deciding whether one filesystem is full.
When space is free and writes still fail
A filesystem can run out of inodes, which are the index entries that point
at files. Disk space is measured in blocks, inodes are counted separately,
and an application sees the same error either way. -i reports
inode usage instead of blocks.
$ df -i /
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/nvme0n1p2 244170752 2890621 241280131 2% /
Two hundred forty four million inodes, 2.8 million in use, two percent.
Nothing wrong here. When that last percentage is at or near 100 with free
space on the volume, you have found the problem, and the cause is almost always a directory with millions of tiny files in it, like a mail queue or a misconfigured cache. On XFS inodes are allocated as needed rather than fixed at format time, so a healthy df -i on RHEL sends you back to the deleted file case below instead. On the fleets I run, df -h and
df -i go together in the first minute of any disk alert,
because the two failures look identical from the outside.
Show the filesystem type
-T adds the type column, which matters when you're deciding
what a filesystem is before you touch it.
$ df -Th /
Filesystem Type Size Used Avail Use% Mounted on
/dev/nvme0n1p2 ext4 3.6T 157G 3.3T 5% /
Use -T on its own and the sizes come back in blocks, which
is why that command is paired with -h here. The type column is
the useful part, and ext4 on a cloud volume tells you nothing
about snapshots, which is the next question you will have.
Why df doesn't move after you delete
This is the call I get most often. Ten gigabytes deleted, percentage unchanged. A process still holds the file open, so the blocks stay allocated with no
name in the tree. The filesystem is correct and the file is gone, only the
handle keeps the space alive.
lsof isn't part of coreutils, so a minimal image usually lacks
it, and it has to run as root to see other users' handles. Run it
as yourself and the interesting lines are usually gone.
$ lsof +L1 | head -3
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NLINK NODE NAME
python3 4148844 deploy 3w REG 259,2 20000000 0 2524663 /tmp/lsof4/t.log (deleted)
+L1 means link count below one, so every line is a file with
no name left. The NLINK column reading zero is the filter
working, and the (deleted) at the end of the name is the
evidence. It also catches memory backed entries, so a few lines whose name
starts with memfd are normal and not your problem.
The recovery that doesn't drop connections is a truncate through the
process's own handle. This box, with a deleted 20 megabyte file still open
and the truncate applied to it.
$ truncate -s 0 /proc/4148844/fd/3
$ lsof +L1 | grep t.log
python3 4148844 deploy 3w REG 259,2 0 0 2524663 /tmp/lsof4/t.log (deleted)
Size went to zero and the blocks came back, with the process still
running. Two rules before you do that on a real box. Check the descriptor
first with ls -l /proc/PID/fd, because the number in this
example means nothing outside this incident. And only truncate a file the
process opened for append or plain write. Truncating under a database, a
WAL or journald is corruption, not recovery, so use reload or restart there
instead.
For a log that keeps growing, the fix upstream is logrotate, because
copytruncate is what creates the situation in the first place.
Restarting the process works too, and it's the wrong first move on a busy
service.
Two other causes are smaller. A filesystem remounted read only after an
I/O error stops updating its numbers, because the kernel has stopped writing
to it, so df reports the last state it cached. The clue is in
the kernel log, and dmesg is restricted on most images now, so
read it with journalctl -k | tail. A remount back to read write
only sticks once the underlying fault is gone, and it fails again if the
device is still erroring. A second mount of the same filesystem, or an NFS
view of it, reports whatever that path last saw.
df and du answer different questions
They aren't two ways of measuring the same thing, and the numbers will
not match. du walks the paths you name and adds up
blocks. df asks the kernel how full the mount is.
$ du -h --max-depth=1 ~ 2>/dev/null | sort -h | tail -4
5.6G /home/deploy/.cache
9.6G /home/deploy/.hermes
31G /home/deploy/code
62G /home/deploy
Sixty two gigabytes of home directory, against 157 gigabytes used on a 3.6
terabyte volume. Both true, and the gap is everything outside a home
directory. Use du to find what is big, and df to
find out whether it matters to the filesystem.
Which one to use, at a glance
| Command | What it does | Reach for it when |
df -h | Space used and free per filesystem | You want the whole picture |
df -h /path | The filesystem that path lives on | You know where the writes are failing |
df -h --total | One summed line | A rough overview is enough |
df -i | Inode usage instead of blocks | Writes fail while space looks free |
df -T | Adds the filesystem type | You don't know what the volume is yet |
df -h -x tmpfs -x devtmpfs | Hides pseudo filesystems | The output is mostly things that aren't disks |
du -sh path | Size of a directory you named | The question is what is big, not what is left |
Verify it works
$ df -h / | tail -1
/dev/nvme0n1p2 3.6T 157G 3.3T 5% /
$ df -i / | tail -1
/dev/nvme0n1p2 244170752 2890621 241280131 2% /
$ df -h -x tmpfs -x devtmpfs
Filesystem Size Used Avail Use% Mounted on
efivarfs 256K 23K 234K 9% /sys/firmware/efi/efivars
/dev/nvme0n1p2 3.6T 157G 3.3T 5% /
/dev/nvme0n1p1 298M 13M 285M 5% /boot/efi
The first two give block and inode usage for the same volume, and the
third drops the memory filesystems so only real devices remain. Check that
the size in the first line matches what you expect for the volume, because a
container showing the host's number is a common surprise.
The honest caveat
Inside a container, df reports the mount it can see, which
is usually the host's overlay, so a pod can honestly show terabytes free.
The limit that kills the pod isn't a filesystem number at all. The kubelet
accounts for the pod's writable layer itself and stops the container when it
passes its ephemeral-storage limit, which is why the two
numbers never disagree in the direction you expect. Check which filesystem
you're looking at before you draw a conclusion, then read the limit itself
with kubectl describe pod and find the writable layer with
du -sh inside the pod.
$ findmnt -no SOURCE,FSTYPE /
/dev/nvme0n1p2 ext4
That's a real disk on this box. Run the same command inside a container
and the answer comes back as overlay overlay, which is the tell
that the number below it belongs to the host.
On a network filesystem df is slow because it asks the
server, and the number it returns is only as current as that server's own
view. On ext4 the filesystem keeps about five percent of the blocks for root by default, so Use% can read 100 while root can still write. XFS reserves nothing for root and it's the default on RHEL, so there the percentage means the same thing for everyone and 100 is 100.
That also explains the small disagreement between commands.
df and lsblk divide by different totals, the space you can write for df and the whole filesystem for lsblk, which is where 5 percent from one and 4 percent from the other come from on the same disk.
The boring conclusion
df -h for room left, df -h /path for one mount,
df -i for the inode failure that looks like free space. Read the
column before you read the percentage, and remember that
du is the command for what is big.
What's the disk alert you have stopped believing?
Frequently asked questions
How do I check disk space in Linux?
Run df -h to see used and available space for every mounted filesystem. For one path, run df -h /path, which reports the filesystem that path lives on rather than the path itself.
What does df -h do?
df reports filesystem usage, the h flag makes the sizes human readable, and the output has one line per mounted filesystem with the size, used, available, percentage and mount point.
What is df -i?
df -i reports inode usage instead of block usage. An inode is the index entry that points at a file, and a filesystem can run out of them while blocks are still free, which produces the same no space left on device error from the application side.
Why does df say no space left when there's free space?
Either the filesystem has run out of inodes, which df -i reports, or a process still holds a deleted file open so the blocks are never freed. Both look like a full disk from the application side.
Why did df not change after deleting files?
A process is still holding a deleted file open, so its blocks stay allocated with no name in the directory tree. Run lsof +L1 to list those, then restart the process that owns them.
What is the difference between df and du?
df asks the kernel how full a mounted filesystem is. du walks the paths you name and adds up blocks. df answers how much room is left, du answers what is big, and the two numbers don't match.
Why does df show different numbers than lsblk?
Both subtract the same blocks that ext4 reserves for root, then divide by different totals, so the same disk reads 5 percent from df and 4 percent from lsblk. The free byte counts match exactly, which is the quick way to prove they agree.
Resources
The reference the command follows, including the reserved block
behaviour that makes the free number smaller than you'd expect.
This builds on how to find a file on linux and sits next to du, which sizes the directory once you know which one is the problem.
For the directory side of the same question, see how to check disk usage with du.