find -exec {} +: Batch Files Into One Call
find -exec CMD {} + appends as many matched paths as fit onto a single command line.
The + terminator turns thousands of per-file calls into a handful of batched ones, the find equivalent of xargs without a pipe.
What it does
find -exec CMD {} + collects matched file names and runs CMD with as many of them as fit within the system argument limit, repeating as needed. It is like \; but batched, so it runs CMD far fewer times. With +, the {} must be the last argument before the plus.
Common usage
find . -name '*.o' -exec rm -f {} +
find . -name '*.go' -exec gofmt -l {} +
find logs -name '*.log' -exec gzip {} +Options
| Form | What it does |
|---|---|
| -exec CMD {} + | Batch many files into one invocation |
| -exec CMD {} \; | One invocation per file (slower) |
| {} + | {} must be the final argument before + |
In CI
Prefer + over \; whenever the command accepts multiple file arguments (rm, grep, gzip, gofmt). For thousands of files it can be orders of magnitude faster because it avoids one fork per file. It also handles spaces in names safely, unlike piping to xargs without -0.
Common errors in CI
"find: missing argument to -exec" with the + form means {} was not immediately before the +; you cannot put extra arguments after {} when using +. If a command does not accept multiple files (it expects exactly one), use \; instead of +.