Skip to content
Nov 3 / Greg

Search Files In Linux For Text String

This is easily accomplished via the grep command.

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

The same search but will go recursively down the structure.

1
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.

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

One Comment

leave a comment
  1. Rob / Nov 3 2010

    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 Comment

 

*