Preface: I understand the difference between -exec {} \; & -exec {} +. I also don't have a problem as such, I am just curious about the semantics of find.
When ending the -exec argument with + instead of ;, we need to end this with {} +, for example:
# FreeBSD find
$ find . -type f -exec cp {} /tmp +
find: -exec: no terminating ";" or "+"
# GNU find is even more cryptic:
$ find: missing argument to `-exec'
Using ; in these examples instead of + works fine (but obviously does something else).
From POSIX:
-exec utility_name [argument ...] ;
-exec utility_name [argument ...] {} +... Only a <plus-sign> that immediately follows an argument containing only the two characters "
{}" shall punctuate the end of the primary expression. Other uses of the <plus-sign> shall not be treated as special.
In other words, when using the +, the command needs to end with {} +.
Why is this? And why only with the + and not the ;? At first I thought maybe to avoid conflicts with filenames that contain a +, but filenames with a ; seem to work fine? I find it hard to believe this limitation is arbitrary ...
The "-exec ... {} +" syntax adopted was a result ofIEEE PASC Interpretation 1003.2 #210and in that document you'll find more details, e.g.:Note that the "+" is only treated as special if it immediately follows "{}". This minimises the chances of causing problems with existing uses of "+" as an argument with "-exec".