What's the + in find /path/ -exec command '{}' + do?

What’s the + in find /path/ -exec command '{}' + do? as opposed to find /path/ -exec command '{}' ;

Asked By: xenoterracide

||

From the man page:

-exec command {} +

This variant of the -exec action runs the specified command on
the selected files, but the command line is built by appending
each selected file name at the end; the total number of invocations of the command will be much less than the number of
matched files. The command line is built in much the same way
that xargs builds its command lines. Only one instance of `{}’
is allowed within the command. The command is executed in the
starting directory.

Answered By: tante

The ‘+’ makes one big command line out of all found files to minimize the number of commands to be run.

Given the case that a find command finds four files.

find . -type f -exec command '{}' ;

would produce

command file1
command file2
command file3
command file4 

On the other hand

find . -type f -exec command '{}' +

produces

command file1 file2 file3 file4
Answered By: ddeimeke
Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.