Find Command – Missing Argument to -exec

find

I'm trying to run the following command:

find a/folder b/folder -name *.c -o -name *.h -exec grep -I foobar '{}' +

This is returning an error:

find: missing argument to -exec

I can't see what's wrong with this command, as it seems to match the man page:

-exec command {} +

This variant of the -exec option 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 invoca-
tions 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.

I also tried:

find a/folder b/folder -name *.c -o -name *.h -exec grep -I foobar {} +
find a/folder b/folder -name *.c -o -name *.h -exec 'grep -I foobar' {} +
find a/folder b/folder -name *.c -o -name *.h -exec 'grep -I foobar' '{}' +
find a/folder b/folder -name "*.c" -o -name "*.h" -exec grep -I foobar '{}' +
find a/folder b/folder \( -name *.c -o -name *.h \) -exec grep -I foobar '{}' +
find a/folder b/folder -name *.c -o -name *.h -exec grep -I foobar '{}' \+

Best Answer

There was several issues with your attempts, including backticks used instead of quotes (removed in later edits to the question), missing quotes where they are required, extra quotes where they are useless, missing parentheses to group -o clauses, and different implementations of findused (see the comments and chat for details).

Anyway, the command can be simplified like this:

find a/folder b/folder -name "*.[ch]" -exec grep -I foobar {} +

or, should you use an archaic GNU find version, this should always work:

find a/folder b/folder -name "*.[ch]" -exec grep -I foobar {} \;
Related Question