LinuxCommandLibrary

du

Show disk space usage

TLDR

List the sizes of a directory and any subdirectories, in the given unit (B/KiB/MiB)

$ du -[b|k|m] [path/to/directory]
copy

List the sizes of a directory and any subdirectories, in human-readable form (i.e. auto-selecting the appropriate unit for each size)
$ du [[-h|--human-readable]] [path/to/directory]
copy

Show the size of a single directory, in human-readable units
$ du [[-sh|--summarize --human-readable]] [path/to/directory]
copy

List the human-readable sizes of a directory and of all the files and directories within it
$ du [[-ah|--all --human-readable]] [path/to/directory]
copy

List the human-readable sizes of a directory and any subdirectories, up to n levels deep
$ du [[-h|--human-readable]] [[-d|--max-depth]] [n] [path/to/directory]
copy

List the human-readable size of all .jpg files in current directory, and show a cumulative total at the end
$ du [[-ch|--total --human-readable]] *.jpg
copy

List all files and directories (including hidden ones) above a certain threshold size (useful for investigating what is actually taking up the space)
$ du [[-ah|--all --human-readable]] [[-t|--threshold]] [1G|1024M|1048576K] .[^.]* *
copy

SYNOPSIS

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

PARAMETERS

-a, --all
    include all files, not just directories

-b, --bytes
    print sizes in bytes, not blocks

-c, --total
    produce a grand total at end

-d, --max-depth=N
    limit output to directories N levels deep; N=0 like -s

-h, --human-readable
    print sizes in human-readable format (e.g., 1K, 2M, 3G)

-H, --si
    human-readable using powers of 1000, not 1024

-k
    like --block-size=1K

-L, --dereference
    dereference symlinks to directories

-l, --count-links
    count hard link sizes multiple times

-m
    like --block-size=1M

-s, --summarize
    display only total for each argument

-S, --separate-dirs
    no recursion into subdirectories

-x, --one-file-system
    skip directories on different filesystems

--apparent-size
    use apparent file sizes, not disk allocation

--exclude=PATTERN
    exclude matching files

DESCRIPTION

du (disk usage) is a core Unix/Linux command for reporting the space used by files and directory trees.

It recursively scans directories, summing the space allocated to all files within, including subdirectories. By default, output shows block counts (typically 1 KiB or 512-byte blocks, system-dependent) for each directory from leaf to root, with totals in the last column.

Essential for system administration, it helps identify large directories, monitor quotas, or debug full disks. Output can be customized with human-readable sizes (-h), summaries (-s), max recursion depth (--max-depth), or filesystem limits (-x).

For instance, du -sh ~/* lists home subdirectory sizes readably; pipe to sort -hr for largest first. Unlike ls, du accounts for full file allocation (including indirect blocks), not just apparent size. It skips hidden files unless specified, and performance scales poorly on massive trees without limits.

CAVEATS

du does not follow symlinks to directories by default (treats as zero-size files); use -L to dereference. Slow on large trees; apparent size (--apparent-size) ignores holes/sparsity. Block sizes vary by system; output order is traversal-based, not sorted.

COMMON EXAMPLES

du -sh *
Human-readable summary of current directory.

du -h --max-depth=1 /var | sort -hr
Largest /var subdirs first.

du -sch .[!.]* *
Include dotfiles and total.

HISTORY

Originated in Version 1 AT&T UNIX (1975); POSIX-specified since 1992. GNU coreutils version (since 1990s) adds options like -h, --max-depth. Maintained by coreutils project.

SEE ALSO

df(1), ls(1), find(1), stat(1)

Copied to clipboard