1835228 Members
2658 Online
110078 Solutions
New Discussion

Re: search commands

 
SOLVED
Go to solution
ChadT
Occasional Advisor

search commands

Is it possible to search directories recursively including the contents of the files. I have tried grep but it will only give me results on my pwd and not drill down through the heirarchy.
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor
Solution

Re: search commands

Hi:

Simply:

# find /pathname -xdev -type f |xargs grep token

Regards!

...JRF...
Matti_Kurkela
Honored Contributor

Re: search commands

Something like:

find /top/directory/of/hierarchy -type f| xargs grep "thing_to_search_for"

should do the trick.

"-type f" means "check the real files only, don't try to open directories like files".
If you want to limit your search to e.g. *.txt files, you could add a "-name '*.txt'" option to the find command (Note the single quotes!).
MK
ChadT
Occasional Advisor

Re: search commands

thank you kindly for the prompt responses...that did the trick.

ChadT
Occasional Advisor

Re: search commands

solution was given by respondants.