The du (disk usage) command estimates how much disk space files and directories occupy. It’s the go-to tool when you need to find what’s consuming space—whether that’s a single file, a project folder, or an entire filesystem. This guide covers the syntax, the options you’ll actually use, and practical examples with their output.
Table of Contents
Syntax
du [OPTIONS] [FILE|DIRECTORY...]
With no arguments, du reports the usage of the current directory and every subdirectory beneath it.
The most useful options
| Option | Meaning |
|---|---|
-h, --human-readable | Human-readable sizes (1K, 234M, 2G) |
-s, --summarize | Show only a total for each argument |
-a, --all | Report files as well as directories |
-c, --total | Print a grand total at the end |
-d N, --max-depth=N | Limit how many directory levels are shown |
--apparent-size | Show apparent size instead of disk usage |
-x, --one-file-system | Skip directories on other filesystems |
--exclude=PATTERN | Skip files/directories matching a pattern |
--time | Show the last modification time |
-t SIZE, --threshold=SIZE | Only show entries at least (or at most) SIZE |
Basic usage
Size of a single file
du -h /etc/passwd
Output:
4.0K /etc/passwd
Size of a directory (recursive listing)
Without -s, du prints every subdirectory:
du -h /var/log
Output:
16K /var/log/apt
4.0K /var/log/private
2.3M /var/log/journal/9f2a
2.3M /var/log/journal
12M /var/log
Total size only with -s
The -s (summarize) flag collapses everything into one line—the most efficient way to size a directory:
du -sh /var/log
Output:
12M /var/log
Common recipes
Size of everything in the current directory
du -sh *
Output:
1.2G Downloads
340M Pictures
28K notes.txt
4.0K todo.md
Include hidden files, and add a grand total
du -sch .[!.]* * | tail -n 1
Or more simply, get one total for the whole current directory:
du -sh .
Output:
See also: Mastering the Linux Command Line — Your Complete Free Training Guide
1.6G .
Limit the depth
Show only the top level of /usr, one directory deep, with a grand total:
du -h --max-depth=1 /usr | sort -rh
Output:
3.9G /usr
2.1G /usr/lib
1.2G /usr/share
480M /usr/bin
120M /usr/include
Find the largest items, biggest first
Pipe du into sort -rh (reverse, human-numeric) to rank by size:
du -sh * | sort -rh | head -n 5
Output:
1.2G Downloads
340M Pictures
96M projects
28K notes.txt
4.0K todo.md
Show every file, not just directories
du -ah /etc/lvm
Output:
96K /etc/lvm/lvm.conf
4.0K /etc/lvm/profile/default.profile
8.0K /etc/lvm/profile
108K /etc/lvm
Exclude files by pattern
Skip .log files when sizing a directory:
du -sh --exclude="*.log" /var/www
Stay on one filesystem
Useful when a directory contains mount points you don’t want to descend into:
du -sh -x /
Only show entries above a size threshold
Report only items larger than 100 MB:
du -h --threshold=100M /home/user
Output:
1.2G /home/user/Downloads
340M /home/user/Pictures
Apparent size vs disk usage
By default, du reports disk usage—the actual number of allocated blocks, which is rounded up to the filesystem block size. --apparent-size reports the file’s logical size instead. The two differ for small files and, dramatically, for sparse files:
du -h --apparent-size sparse.img
du -h sparse.img
Output:
1.0G sparse.img
4.0K sparse.img
The first line is what you’d read out of the file; the second is what it actually occupies on disk. When you care about real storage consumed, use the default (disk usage), not --apparent-size.
Reporting in specific units
du -k /etc/hosts # size in kilobytes (1K blocks)
du -m /var/log # size in megabytes
du -b /etc/hostname # apparent size in bytes
du --si -s /var # powers of 1000 (kB/MB/GB) instead of 1024
Output:
4 /etc/hosts
12 /var/log
26 /etc/hostname
13M /var
Note the difference between -h (base 1024: KiB/MiB) and --si (base 1000: kB/MB). A directory shown as 12M by -h may read as 13M under --si.
Extract just the size in a script
du puts the size in the first column, so pull it out with awk or cut:
filesize=$(du -sh /etc/passwd | awk '{print $1}')
echo "$filesize"
Output:
4.0K
du vs df
These two are easy to confuse:
duworks bottom-up, adding up the space used by files and directories you point it at. Answer: “How much space is this directory using?”dfreads filesystem-level accounting from the superblock. Answer: “How much space is free on this filesystem?”
They can disagree—for example, a deleted file still held open by a running process no longer appears to du, but its blocks are still counted by df until the process closes it.
df -h /
Output:
Filesystem Size Used Avail Use% Mounted on
/dev/nvme0n1p2 468G 210G 234G 48% /
Summary
- Use
du -sh dirfor a quick total of a directory. - Use
du -h --max-depth=1 dir | sort -rhto see where space goes, one level down, largest first. - Use
du -sh * | sort -rh | headto rank the biggest items in a folder. - Remember that
dureports disk usage by default; add--apparent-sizeonly when you want logical file sizes. - Reach for
df(notdu) when you want free space on a whole filesystem.


