I have some times come across the use of trailing +
while using unix commands like find
.
Example from SO post -
find -exec touch -t 201007162310.00 \+
Please help me understand the use of this.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityFrom man find
:
-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.
For example with find -exec touch -t 201007162310.00 \+
, if the find command without the -exec
gives you the files 1.txt
, 2.txt
and 3.txt
, it will exec:
touch -t 201007162310.00 1.txt
touch -t 201007162310.00 2.txt
touch -t 201007162310.00 3.txt
without the \+
, and
touch -t 201007162310.00 1.txt 2.txt 3.txt
with the \+
.
The latter version is faster due to a (much) smaller number of new processes needed yet it is less portable (not all find
implementations support it). And of course, if the command you try to -exec
doesn't support receiving multiple files as arguments, it won't work.
-exec {} +
is POSIX and standard. For once, only the GNU find was not supporting it until findutils
4.2.12 (2005). -exec {} +
was added to SysV some time in the 80s by David Korn.
Jun 7, 2013 at 15:03
-exec
can take a+
option to mimic the behaviour ofxargs
”.