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.

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

share|improve this question
add comment

2 Answers

up vote 12 down vote accepted

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
share|improve this answer
3  
If you know xargs, -exec … {} + does the same as -print | xargs …, but without the quoting issues (-print0 | xargs -0 is another way, but it's less portable). –  Gilles Nov 1 '10 at 18:13
add comment

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.

share|improve this answer
1  
man that's very... terse? I find it to be lacking in depth, and clarity. –  xenoterracide Nov 1 '10 at 12:54
    
The idea is not to blindly spawn one process for each file, but to gather the filenames together and call the command fewer times. An example: instead of creating 3 different "rm FILENAME" processes, it gathers the filenames and does "rm FILE1 FILE2 FILE3". –  tante Nov 1 '10 at 13:02
    
IIRC some versions of xargs have an option to batch these names together up to a specified limit, so you can benefit from this but also avoid overflowing when you have a large list, too. –  Kevin Cantu Nov 2 '10 at 2:03
    
(Find, itself, is a scary little language all its own!) –  Kevin Cantu Nov 2 '10 at 2:03
    
find gives me a semi. –  Matt Alexander Jan 29 '11 at 21:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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