Skip to content
Latchkey

find -printf: Custom Output Formats (GNU)

find -printf prints a custom format string for each match, with directives for size, time, and path.

For reports and sortable output, -printf beats parsing -ls. It is a GNU extension, so know the fallback for macOS runners.

What it does

find -printf FORMAT prints FORMAT for each match, expanding directives such as %p (path), %f (base name), %s (size in bytes), %TY-%Tm-%Td (modification date), and %y (type). Unlike -print it adds no trailing newline unless you include \n.

Common usage

Terminal
find . -type f -printf '%s %p\n' | sort -n
find . -type f -printf '%TY-%Tm-%Td %p\n'
find . -type f -printf '%f\n'

Options

DirectiveWhat it does
%pFull path of the file
%fBase name only
%sSize in bytes
%yType letter (f, d, l, ...)
%TY-%Tm-%TdModification date (year-month-day)
\nNewline (must be included explicitly)

In CI

find . -type f -printf "%s %p\n" | sort -n lists files by size, ideal for finding what filled the disk. Because -printf is GNU only, a script using it breaks on macOS runners; guard it or fall back to -exec stat -f or -ls there.

Common errors in CI

"find: unknown predicate '-printf'" means BSD/macOS find, which has no -printf; use stat via -exec, or GNU find (gfind from coreutils on Homebrew). Forgetting \n in the format glues all output onto one line. A literal % must be written as %%.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →