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
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
| Directive | What it does |
|---|---|
| %p | Full path of the file |
| %f | Base name only |
| %s | Size in bytes |
| %y | Type letter (f, d, l, ...) |
| %TY-%Tm-%Td | Modification date (year-month-day) |
| \n | Newline (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 %%.