Find the largest files in a directory
Identify the top N largest files under a directory tree, sorted by size.
How to find the largest files in a directory in each shell
Bashunix
find . -type f -exec du -h {} + | sort -rh | head -10`-exec du -h {} +` batches arguments — much faster than `\;` which forks once per file.
Zshunix
find . -type f -exec du -h {} + | sort -rh | head -10Fishunix
find . -type f -exec du -h {} + | sort -rh | head -10PowerShellwindows
Get-ChildItem -Recurse -File | Sort-Object Length -Descending | Select-Object -First 10 FullName, Length`Length` is in bytes. Pipe through `Format-Table -AutoSize` for human-readable display.
cmd.exewindows
powershell -NoProfile -Command "Get-ChildItem -Recurse -File | Sort-Object Length -Descending | Select-Object -First 10 FullName, Length"cmd has no built-in size aggregation. Shell out to PowerShell — present on every Windows install since 7.
Equivalents listed for Bash, Zsh, Fish, PowerShell, cmd.exe.
Gotchas & notes
- `du -h` shows **disk allocated** size (block-aligned), which can exceed apparent size for many small files. Use `du -h --apparent-size` (GNU) to match `ls -l`.
- `sort -rh` requires GNU sort's `-h` (human-numeric) flag — present on Linux, optional on macOS (`brew install coreutils` gives `gsort`).
- For directory totals rather than per-file sizes: `du -sh */ | sort -rh | head -10`.
- PowerShell `Length` is byte count of files; for **folder** totals use `(Get-ChildItem -Recurse -File | Measure-Object Length -Sum).Sum`.