Find the largest files
Lists the largest files under a directory, human-readable and sorted biggest-first, using only find, sort and head — no extra tools.
Last updated
find . -type f -exec du -h {} \; | sort -rh | head -n 10How it works
find . -type f -exec du -h {} \; runs du -h once per file (the \; form, as opposed to the batching +), printing each one's human-readable size and path on its own line — that per-file invocation is what makes the du -h output line up cleanly for sort -h to compare, instead of a directory's rolled-up total mixing into the list.
sort -rh understands human-readable size suffixes directly (1K, 1M, 1G) and orders them by actual magnitude rather than alphabetically — without -h, plain sort -r would put "9K" ahead of "1G" because it's comparing the leading digit as text. head -n 10 then trims the sorted output to the top 10; change that number for more or fewer results.
Edge cases to know
- →sort -h is a GNU coreutils extension. It works as shown on Linux and on macOS if you've installed GNU coreutils (gsort -h), but the system sort that ships with macOS/BSD has no -h flag — there you'd sort on raw byte counts instead (du -k, then sort -rn) and format afterward.
- →Symlinked files are followed by default in some find implementations and not others; add -not -type l or a -follow flag deliberately if your directory tree includes symlinks you want to include or exclude on purpose.
- →Permission-denied directories print a "Permission denied" line to stderr for every one they hit — redirect with 2>/dev/null if you only want the size listing and are fine losing that warning.