macOS – How to Identify Largest Files in a Directory Including Subdirectories

bashcommand linemacosterminalzsh

I have a directory with a lot of files and subdirectories. I know there are a small number of large files contained somewhere within. What is a quick/easy way to identify one or more large files in a directory, including throughout all it's sub directories?

I tried this:

find . -printf '%s %p\n'|sort -nr|head
find: -printf: unknown primary or operator

and this:

find -type f -printf '%s %p\n' |sort -nr | head

find: illegal option -- t
usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression]
       find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]

and this:

find . -type f -printf "%s %p\n" | sort -nr | head -1
find: -printf: unknown primary or operator

Best Answer

Here's an example using BSD find and stat-

find . -type f -exec stat -f '%z %N' {} + | sort -nr