Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

up vote 6 down vote accepted
find . -type f | xargs grep -l "search-pattern" 

or

grep -R "search pattern" *
share|improve this answer
    
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

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.

share|improve this answer
    
i feel so lame for not trying -R :( thanks dude –  Itai Ganot Dec 26 '12 at 17:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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