Search Recursively for Text in Files


-R

The * wildcard allows you to search several files in the same directory, but to search in several subdirectories at once, you need the -R (or --recursive) option. Let's look for the word hideous, a favorite of horror writers of the nineteenth and early twentieth centuries, amongst a collection of old-fashioned (but still wonderful!) tales.

$ grep -R hideous * machen/great_god_pan.txt:know, not in your most fantastic, hideous dreams can you have machen/great_god_pan.txt:hideously contorted in the entire course of my practice, and I machen/great_god_pan.txt:death was horrible. The blackened face, the hideous form upon lovecraft/Beyond the Wall of Sleep.txt:some hideous but unnamed wrong, which lovecraft/Beyond the Wall of Sleep.txt:blanket over the hideous face, and awakened the nurse. lovecraft/Call of Cthulhu.txt:hideous a chain. I think that the professor, too, intended to lovecraft/Call of Cthulhu.txt:voodoo meeting; and so singular and hideous were the rites lovecraft/Call of Cthulhu.txt:stated, a very crude bas-relief of stone, comprising a hideous... 


Tip

Of course, if you get too many results, you should pipe the results to less, as you did previously with locate in "Manage Results Received When Searching a Database of Filenames":

$ grep -R hideous *| less 


Another tactic would be to send the output of the command into a text file, and then open that file in whatever text editor you prefer:

$ grep -R hideous * > hideous_in_horror.txt 


That's a great way to search and store your results in case you need them later.




Linux Phrasebook
Linux Phrasebook
ISBN: 0672328380
EAN: 2147483647
Year: 2007
Pages: 288

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net