Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

This question already has an answer here:

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.

share|improve this question
    
No explanation in Find -exec + vs find | xargs. Which one to choose?? –  manatwork Jun 7 '13 at 13:25
    
I don't see this as a duplicate of q#41740. This question asks "what", the other "why". –  phunehehe Jun 7 '13 at 14:48
    
Neither I consider it exact duplicate, however that question's first sentence definitely answers this one: “the -exec can take a + option to mimic the behaviour of xargs”. –  manatwork Jun 7 '13 at 14:53
1  
Did you even look at the man page before asking this question? –  mdpc Jun 7 '13 at 16:13
    
@mdpc no. not yet got to completely read a man page yet ;) –  mtk Jun 7 '13 at 17:17
add comment

marked as duplicate by slm, Anthon, l0b0, Hauke Laging, Renan Jun 7 '13 at 20:27

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

From 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.

share|improve this answer
    
thank you @peterph for editing –  lgeorget Jun 7 '13 at 13:40
2  
-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. –  Stephane Chazelas Jun 7 '13 at 15:03
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.