Networking • Automation • Occasional Podcasting
,

Search Files In Linux For Text String

This is easily accomplished via the grep command.

grep “find text” /home/greg/*.txt

The same search but will go recursively down the structure.

grep -r “find text” /home/greg/*.txt

The following is recursion and it will also print the file name that the text was found in.

grep -H -r “find text” /home/greg/*.txt

Comments

One response to “Search Files In Linux For Text String”

  1. Rob Avatar

    One of my favorite’s:

    grep -R -B3 -A3 “find text” /var/log/

    Recursively returns 3 lines before and 3 lines after with a match. 😀

Leave a Reply

Your email address will not be published. Required fields are marked *