Grep....

hi all

I want to grep in a list of files a string but the output is :

/bin/grep: Argument list too long.

How can i do to correct the error .
Thanks a lot

Depends what you're doing.

Show your code.

In most cases this is because of a wildcard expanding to too many filenames, like this:

grep "foo" *

where * expands to many thousands of filenames. The simple answer: don't use wildcards in scripts if you are not 100% sure that cannot happen.

Use find instead, like this:

find /some/where -type f -exec grep "foo" {} \;

I hope this helps, but what Corona688 said still stands: instead of making us guessing wildly about what maybe could be the problem you should simply show what you have done.

bakunin

With the classic /dev/null trick it prefixes the filename

find /some/where -type f -exec grep "foo" /dev/null {} \;

Or a bit faster, run grep with multi arguments (and still avoid two many arguments)

find /some/where -type f -exec grep "foo" /dev/null {} +

In the latter case the /dev/null is needed only for the case there is one grep argument.
Some grep versions take a -H option to achieve the same

find /some/where -type f -exec grep -H "foo" {} +