df and du Commands in Linux: Disk Space Syntax, Options & Examples

df reports free and used space on mounted file systems. du walks directories and sums how much disk space files and folders consume — use df for mount points, du to find what is filling a path.

Published

Updated

Read time 11 min read

Reviewed byDeepak Prasad

df and du Commands in Linux: Disk Space Syntax, Options & Examples
About df reports free and used space on mounted file systems. du walks directories and sums how much disk space files and folders consume — use df for mount points, du to find what is filling a path.
Tested on Ubuntu 25.04 (Plucky Puffin); df (GNU coreutils) 9.5; du (uutils coreutils) 0.2.2; kernel 7.0.0-27-generic
Package coreutils / uutils-coreutils (apt/deb) · coreutils (dnf/rpm)
Man page df / du(1)
Privilege user (read access to paths)
Distros

df and du ship on every major Linux distro (GNU coreutils or compatible builds).

On Ubuntu 25.04, df is GNU coreutils 9.5 (/usr/bin/gnudf); du is uutils coreutils 0.2.2 — flags match for everyday use; see du --help on your host for edge-case differences.

Related guide

df — quick reference

File system summary

Show how full each mounted file system is — block usage, mount point, and (optionally) file system type.

When to use Command
Human-readable space for one path or mount df -h /
Include file system type column df -hT /
List inode usage instead of blocks df -i /
Grand total row across listed file systems df -h --total
Only local file systems (skip NFS, etc.) df -lh
Hide file systems of a given type df -h -x tmpfs -x devtmpfs /
Show only one file system type df -h -t ext4
Custom columns (source, size, used, mount) df --output=source,fstype,size,used,avail,pcent,target /
POSIX portable column layout df -P -h /
Fixed block unit (megabytes) df -B M /tmp
Decimal SI units (1000-based) df -H /
Show brief usage df --help
Show package version df --version

du — quick reference

Directory and file usage

Walk paths and print how much space they use — per file, per subdirectory, or as one total.

When to use Command
Total size of one directory du -sh /path/to/dir
Size of each immediate subdirectory du -h --max-depth=1 /path/to/dir
List every file and directory with sizes du -ah /path/to/dir
Grand total when summing several paths du -ch /path/*
Skip files matching a pattern du -sh --exclude='*.bin' /path/to/dir
Apparent byte size (not disk blocks) du -sb /path/to/dir
Stay on the same file system (skip mounts below) du -x -sh /path/to/dir
Only show entries above a size threshold du -t 1M -h /path/to/dir
Directory size without counting subdirs inside it du -S /path/to/subdir
Count hard-linked file size multiple times du -l /path/file1 /path/hardlink
SI human units (1000-based) du --si -sh /path/to/dir
One-line total per argument only du -s /path/to/dir
Show last modification time per entry du --time /path/to/dir
Show brief usage du --help
Show package version du --version

df and du — command syntax

Synopsis from df --help and du --help on Ubuntu 25.04:

text
df [OPTION]... [FILE]...

du [OPTION]... [FILE]...
       du [OPTION]... --files0-from=F

df reads file system statistics from mounted volumes — it does not scan every file. du walks the directory tree under each path you name. Both default to 1024-byte units unless you pass -h, -H, --si, or -B.


df and du — command examples

Essential Check free space on the root file system

When a server reports "disk full", start with df on the mount you care about — here the root file system /.

Run the command:

bash
df -h /

Sample output:

text
Filesystem                         Size  Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv   58G   20G   36G  36% /

The Avail column is free space for new writes. Use% near 100% means you should free space or grow the volume before applications fail.

Essential Find which directories use the most space

df tells you a mount is full; du shows which folders under a path account for the usage.

Run the commands:

bash
du -sh /var/log
du -h --max-depth=1 /var/log

Sample output (sizes vary by host):

text
167M	/var/log
150M	/var/log/journal
4.0K	/var/log/cups-browsed
1.1M	/var/log/sysstat
4.0K	/var/log/private
1.1M	/var/log/installer
1.5M	/var/log/dist-upgrade
316K	/var/log/apt

The first line is the total under /var/log. The second command breaks that down one level — here journal is the main consumer. Drill into the largest line with another du -h --max-depth=1 on that subdirectory.

Essential Add up several paths with a grand total

Use -c when you pass multiple files or directories and want a total line at the end — handy in scripts and quick audits.

Run the command (test tree under /tmp):

bash
du -ch /tmp/glc-dfdu-test/*

Sample output:

text
2.0M	/tmp/glc-dfdu-test/big.bin
4.0K	/tmp/glc-dfdu-test/file1.txt
4.0K	/tmp/glc-dfdu-test/hardlink.txt
0	/tmp/glc-dfdu-test/sub1/sub2
4.0K	/tmp/glc-dfdu-test/sub1
2.1M	total

The total row is the sum of all arguments. Pair with sort -h when you need the largest paths first: du -ch /path/* | sort -h.

Common Check inode usage before 'no space left' with free blocks

A file system can run out of inodes (file metadata slots) even when df -h still shows free blocks — common with millions of tiny files.

Run the command:

bash
df -i /

Sample output:

text
Filesystem                         Inodes  IUsed   IFree IUse% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv 3833856 308647 3525209    9% /

Watch IUse%. If it approaches 100%, delete or archive small files, or reformat with more inodes — adding block space alone will not help.

Common Skip noisy paths when measuring a directory

Log trees and build caches often contain huge files you want to ignore in a quick size check. --exclude accepts shell-style globs.

Run the command:

bash
du -sh --exclude='*.bin' /tmp/glc-dfdu-test

Sample output:

text
8.0K	/tmp/glc-dfdu-test

Without the exclude, the same tree reported about 2.1M because of big.bin. For patterns in a file, use du -X /path/to/exclude.lst /path/to/dir.

Common Why df and du totals differ on the same mount

Admins often compare df on / with du -x / and see different numbers. That is normal — deleted files still held open, reserved blocks, and metadata all affect df but not a full du walk.

Check mount-level free space:

bash
df -h /

Sample output:

text
Filesystem                         Size  Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv   58G   20G   36G  36% /

Sum usage on the same file system only (-x skips other mounts encountered below):

bash
sudo du -xh --max-depth=1 / 2>/dev/null | tail -5

du must read directories you are allowed to traverse; redirect errors to /dev/null or run with appropriate privileges. The df Used column includes space you cannot attribute to any visible path (open-but-deleted logs are a frequent cause). Use lsof +L1 to find deleted files still held open.

Common Script-friendly df columns

For monitoring scripts, --output picks exactly the fields you need — no parsing the default six-column table.

Run the command:

bash
df --output=source,fstype,size,used,avail,pcent,target /

Sample output:

text
Filesystem                        Type 1K-blocks     Used    Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv ext4  60104848 20161912 37235564  36% /

Combine with -h for human sizes, or omit it when your collector expects 1K-blocks.

Advanced Filter small entries and show directory ages

-t hides entries below a threshold so you only see large consumers. --time adds the newest modification time under each directory — helpful when hunting recent growth.

Run the commands:

bash
du -t 1M -h /tmp/glc-dfdu-test
du --time /tmp/glc-dfdu-test

Sample output:

text
2.1M	/tmp/glc-dfdu-test
0	2026-07-01 19:06	/tmp/glc-dfdu-test/sub1/sub2
4	2026-07-01 19:06	/tmp/glc-dfdu-test/sub1
2056	2026-07-01 19:06	/tmp/glc-dfdu-test

Only big.bin and the directory total met the 1M threshold. The --time column reflects the latest file mtime in each subtree.


df and du — when to use / when not

Use df / du when Use something else when
  • You need a quick answer for how full a mount point is → df -h
  • You need to find which directories or files consume space under a path → du -sh and du -h --max-depth=1
  • You suspect an inode shortage → df -i
  • You are scripting alerts or dashboards with fixed columns → df --output=…
  • You want totals for several folders in one run → du -ch
  • You need a live, updating view of I/O and CPU per process → top, htop, or iotop
  • You need block-device layout (partitions, LVM) → lsblk, pvs, vgs, lvs
  • You need to find files by name, age, or size across trees → find
  • You need per-directory disk usage with a navigable TUI → ncdu (extra package)
  • You need file system creation or resize → mkfs, resize2fs, LVM tools — not df/du

df vs du

df du
What it measures Free/used space on mounted file systems Space used by files and directories you name
How it works Reads file system metadata (fast) Walks the directory tree (slower on large trees)
Open deleted files Counts their blocks in Used Does not see them (no directory entry)
Best first question "Is / full?" "What under /var is huge?"

Use both together: df -h to confirm the problem mount, then du on the busiest path to find cleanup targets.


Commands admins often run in the same troubleshooting session — layout, search, and file system maintenance.

Command One line
df / du Mount usage and per-path totals (this page)
find Locate large or old files by criteria
lsblk Block devices, partitions, and mount points
tune2fs ext2/3/4 parameters and reserved block counts
LVM shrink Reduce a logical volume when free space allows

Browse the full index on the Linux commands cheat sheet.


df and du — interview corner

What is the difference between df and du in Linux?

df (disk free) reports space at the file system level — how much of each mounted volume is used and available. It is fast because it reads superblock statistics.

du (disk usage) walks a directory tree and sums the space used by files and subdirectories you point it at. It answers "what is using space here?" rather than "how full is the mount?"

They often disagree: df includes blocks held by deleted-but-still-open files; du only counts paths that still exist in the directory hierarchy.

A strong answer is:

"df tells me how full a mount is; du tells me which paths consume space under that mount. I use df first for alerts, then du to find cleanup targets."

What does df -h show?

-h prints sizes in human-readable units (K, M, G) using powers of 1024. Each row is one file system: device or source, total size, used, available, use percentage, and mount point.

bash
df -h /

Typical columns: Size, Used, Avail, Use%, Mounted on. For automation, --output selects specific fields; -i switches the report to inode counts instead of blocks.

A strong answer is:

"df -h is the quick health check for mount points — human-readable used and available space. I add -i when I suspect inode exhaustion, and --output for scripts."

What does du -sh do?

-s (summarize) prints one total per argument instead of every subdirectory. -h makes that total human-readable.

bash
du -sh /var/log

Useful follow-up when a directory is large:

bash
du -h --max-depth=1 /var/log | sort -h

That lists immediate children sorted by size so you can drill into the biggest folder.

A strong answer is:

"du -sh gives a single total for a path; I combine it with --max-depth=1 and sort -h to find which subdirectory grew."

Can a disk be full even when df shows free space?

Yes — two common cases:

  1. Inode exhaustion — millions of tiny files use all inode slots while many blocks remain. Check with df -i; IUse% near 100% is the signal.
  2. Reserved blocks — ext file systems reserve a percentage for root; unprivileged users may see "no space" while df still shows some Avail for root.

Also compare df Used with du -x on the mount: a large gap often means deleted files still held open by daemons.

A strong answer is:

"I check df -i for inode exhaustion, remember root-reserved blocks on ext, and compare df with du when open deleted files might be holding space."

Why might du behave differently on Ubuntu 25.04?

On Ubuntu 25.04, df comes from GNU coreutils 9.5 while du may come from uutils coreutils 0.2.2 (/usr/lib/cargo/bin/coreutils/du). Everyday flags (-sh, --max-depth, --exclude, -x, -t) match GNU behaviour on this page.

For portable scripts, always run du --help on the target host. If you need strict GNU semantics everywhere, install the coreutils package and call the GNU binary explicitly.

A strong answer is:

"Ubuntu 25.04 can ship uutils du alongside GNU df — I verify flags with du --help on the host and pin GNU coreutils in scripts when behaviour must be identical."


Troubleshooting

Symptom Likely cause Fix
df and du totals differ a lot Open deleted files, reserved blocks, or mount-point mismatch lsof +L1; use du -x on the same mount; check ext reserved blocks with tune2fs -l
No space left on device but df shows free space Inode exhaustion df -i; delete or archive small files; rebuild FS with more inodes if needed
du: cannot read directory Permission denied on subtrees Run with sudo or exclude unreadable paths; redirect errors in scripts
du much slower than df Full tree walk on millions of files Use --max-depth, --exclude, or ncdu; target the busiest parent first
df: /path: No such file or directory Path is not a mount point or typo Pass an existing path on the file system, or run plain df -h for all mounts
Unexpected units Missing -h / -H / --si Add -h (1024) or --si (1000); use -B for fixed block size

References

Further reading — man pages and related storage guides.

Rohan Timalsina

is a technical writer and Linux enthusiast who writes practical guides on Linux commands and system administration. He focuses on simplifying complex topics through clear explanations.