up vote 2 down vote favorite
share [g+] share [fb]

I'm trying to use the + option of find exec instead of xargs. However, I can't seem to get it to work. I feel I must be missing something obvious here.

Example:

find . -name "*.java" -exec grep "@author" {} + \;
find: paths must precede expression
Usage: find [-H] [-L] [-P] [path...] [expression]

On the other hand, this works:

find . -name "*.java" -exec grep "@author" {}  \;

as does this:

find . -name "*.java" | xargs  grep "@author"
link|improve this question

71% accept rate
feedback

2 Answers

up vote 3 down vote accepted

You don't need \; together with +

link|improve this answer
1  
find . -name "*.java" -exec grep "@author" {} + – Dennis Williamson Sep 11 '09 at 8:45
feedback

It's much easier just to use find -print0 | xargs --null -I XXX do_something XXX. Let find to the finding and xargs do the, er, other stuff.

link|improve this answer
If you use find -print0, you need -0 for xargs. – Doug Harris Oct 8 '09 at 18:15
-0 is the short version of --null. – Ryan Thompson Oct 8 '09 at 22:22
feedback

Your Answer

 
or
required, but never shown

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