Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • 2
    This won't work if there are a lot of files in the directory, it will throw the error "zsh: argument list too long: grep". Any ideas on how to get rid of this? Commented Mar 2, 2012 at 6:17
  • 3
    @user16142 grep the directory instead of the files: grep -lr "string" directory | wc -l If you don't want recursive search, you can use find with maxdepth option: find directory -maxdepth 1 -type f -exec grep -l "string" {} + | wc -l Note that this second option is slower than grep. Commented Oct 17, 2017 at 0:09
  • I have to use grep -l "string" * |& wc -l Commented Feb 27, 2022 at 14:31