Search code examples
shellcommand-linegrepcommandglob

Too many arguments for grep?


Here's what I'm trying to run:

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

Here's the error I'm getting:

Argument list too long

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

I've seen several questions related to this error, but none of them seem to focus on counting the results afterwards. Any suggestions would be appreciated.


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