3

I usually use grep word * while being in a folder which includes files that have that word. But in this folder i also have folders which under them there are files that have that word, what is the correct command for this matter please?

Thanks

Itai Ganot
  • 10,644
  • 29
  • 93
  • 146

2 Answers2

6
find . -type f | xargs grep -l "search-pattern" 

or

grep -R "search pattern" *
user9517
  • 115,471
  • 20
  • 215
  • 297
colealtdelete
  • 6,017
  • 2
  • 30
  • 34
  • When used right, `grep -R` can save hours. For example, I was editing a JSP application, and needed to find the file related to a web page I was seeing. A quick copy-and-paste of one HTML line into grep, and the related file appears in the terminal. Not recommended for larger applications, or slow machines ;) – Soviero Dec 26 '12 at 15:35
5

There's a recursive option to grep:

grep -R word *

You can replace "*" with a full path to a directory that you want to look at as using a wildcard will search for the word "word" in current directory.

Ernestas
  • 23
  • 6
John
  • 9,070
  • 1
  • 29
  • 34