du

Updated

September 4, 2026

Overview

du estimates file and directory space usage by walking the tree. Use it after df shows a full mount to find which directories consume space. For interactive exploration, prefer ncdu/dust; for scripts, du -sb or du -sh.

Syntax

du [options] [file...]

Common Options

Option Description
-h Human-readable
-s Summarize (total only)
-a All files, not just dirs
-c Grand total
-d N, --max-depth=N Limit depth
-x One filesystem only
-b / -k / -m Bytes / KiB / MiB
--apparent-size Logical size vs allocated blocks
-L Follow symlinks
--exclude=PATTERN Skip matching paths
-t SIZE Threshold (GNU)
--inodes Count inodes (GNU)
-0 NUL-terminated output

Examples with Explanations

Top-level breakdown

du -h -d 1 /var 2>/dev/null | sort -h
du -sh /var/*

Summaries

du -sh .
du -sh /home/*
du -c -sh /var/log /var/cache

One filesystem (skip mounts)

du -x -h -d 1 /

Avoids descending into /mnt, network mounts, etc.

Apparent vs allocated

du -sh file.img
du -sh --apparent-size file.img
# sparse files differ a lot

Exclude noise

du -sh --exclude='.git' --exclude='node_modules' *

Sort biggest

du -h -d 1 | sort -h
du -h -d 2 /var | sort -h | tail

Scripts (bytes)

du -sb /var/lib/myapp | awk '{print $1}'

Find large files (pair with find)

find /var -xdev -type f -size +1G -exec ls -lh {} \;
du -ah /var 2>/dev/null | sort -h | tail -20

Notes / Pitfalls

  • Permission denied dirs undercount silently unless stderr watched.
  • Hard links: GNU du counts once per tree walk by default when possible.
  • Different mounts under a path inflate totals unless -x.
  • Snapshots (btrfs/zfs) make “usage” subtle — use native tools for pool accounting.
  • sort -h needs human units from du -h.

2026-relevant notes

  • Interactive: dust, ncdu, dua. Scripts: stick to du.
  • Container graph drivers: measure the host path carefully; overlay layers confuse naive du.
  • Combine df (full?) + du (where?) + lsof (deleted open files).

Additional Resources

  • man du