shellcommand-linegrepcommandglob

Too many arguments for grep?


Here's what I'm running:

grep "this is a test" * | wc -l

Here's the error:

Argument list too long

I want to count how many files in a directory have a specific string in them.

I've seen several related questions, but none of them seem to focus on counting the results afterwards.


Solution

  • You might be having too many file in current directory.

    You can use find with -exec option for this:

    find . -maxdepth 1 -type f -exec grep 'this is a test' '{}' + | wc -l