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?



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.

  • i feel so lame for not trying -R :( thanks dude
    – Itai Ganot
    Dec 26 '12 at 17:16
find . -type f | xargs grep -l "search-pattern" 


grep -R "search pattern" *
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.