du — Summarize disk usage of files and directories across all 5 shells
Equivalents in every shell
du -sh *`-s` is SUMMARY (one line per arg, not the whole walked tree); `-h` is HUMAN-READABLE. Without `-s` you get every subdirectory recursively — for top-level breakdown of cwd: `du -h -d 1` (GNU) or `du -h --max-depth=1`. BSD/macOS `du` uses `-d 1` only; `--max-depth` is GNU-specific.
du -sh *Same `/usr/bin/du`. macOS ships BSD `du` — `du -d 1 -h` works; `du --max-depth` errors. For sorted output across platforms: `du -sh */ | sort -h` (GNU `sort -h` understands "1.5G", "500M" — BSD `sort` does not; use `sort -k1,1nr` instead).
du -sh *Same external. Fish glob `du -sh **/*` recurses through all subdirectories — usually too noisy; prefer `du -sh */` for top-level dirs or `ncdu` for interactive exploration.
Get-ChildItem -Recurse | Measure-Object Length -SumNo native `du` cmdlet. The idiom is to recursively enumerate and sum `.Length`. WARNING: `Get-ChildItem -Recurse` does NOT follow symlinks by default (PS 6+); on PS 5.1 it does, and may follow them into infinite loops. For one-line GBs: `"{0:N1} GB" -f ((Get-ChildItem -Recurse | Measure-Object Length -Sum).Sum/1GB)`.
dir /s /-c`/s` recurses; `/-c` omits the thousands separator. Output shows total bytes per directory at the bottom of each section, plus a grand total. No per-subdirectory summary — for that, use PowerShell or install `du.exe` from Sysinternals.
Worked examples
Top-level breakdown of disk usage in cwd (one line per subdir)
du -h -d 1 | sort -hdu -h -d 1 | sort -hGet-ChildItem -Directory | ForEach-Object { [PSCustomObject]@{ Name=$_.Name; SizeMB=[math]::Round((Get-ChildItem $_ -Recurse -File | Measure-Object Length -Sum).Sum/1MB,1) } } | Sort-Object SizeMB -DescendingTotal size of one directory (single number)
du -sh ./node_modules"{0:N1} MB" -f ((Get-ChildItem ./node_modules -Recurse -File | Measure-Object Length -Sum).Sum/1MB)dir /s /-c node_modulesFind the 10 largest items in cwd
du -ah . | sort -hr | head -10Get-ChildItem -Recurse -File | Sort-Object Length -Descending | Select-Object -First 10 FullName, LengthGotchas
- BSD `du` (macOS, FreeBSD) accepts `-d N` for max-depth; GNU `du` (Linux) accepts BOTH `-d N` and `--max-depth=N`. Scripts portable across both should stick to short `-d 1` and avoid the long form.
- `du` counts disk BLOCKS, not byte length — a 1-byte file may show as 4 KB on a filesystem with 4 KB blocks. For exact byte counts use `du -b` (GNU only) or `find . -type f -printf "%s\n" | paste -sd+ | bc`. PowerShell `Measure-Object Length -Sum` returns true byte length.
- Hardlinks are counted ONCE by default — `du` walks inode numbers and skips duplicates. This is why `du /` and `du /usr` may not add up to the parent total. PowerShell's `Get-ChildItem -Recurse | Measure-Object Length -Sum` has NO inode awareness — hardlinks are double-counted, producing larger sums than `du` for trees with hardlink-deduplication (e.g. Time Machine backups).
- Symlink-traversal differs between tools. `du` does NOT follow symlinks by default (`-L` forces it); GNU `find -printf` does NOT either (use `-L find`); PowerShell `Get-ChildItem -Recurse` does follow symlinks on PS 5.1 (Windows-builtin) and DOES NOT on PS 7+. Mixed-version pipelines can produce wildly different totals.
- For interactive exploration, `ncdu` (`brew install ncdu`, `apt install ncdu`) is dramatically better than raw `du` — full-screen TUI sorted by size with j/k navigation. Windows analog: `WinDirStat` (GUI) or `ncdu` inside WSL targeting `/mnt/c/...`.
WSL & PowerShell Core notes
Common tasks using du
- Check free disk space
Show free and used space per filesystem (or per drive) in a human-readable form.
- Find files larger than 100MB
List files exceeding a size threshold — useful for cleanup, quota enforcement, and identifying log-rotation gaps.
- Get a file size in bytes
Print the size of a file in bytes — for quotas, validation, and disk-usage scripts.