How to find a particular text string in Linux

You need to use the grep command. The grep command searches the given input FILEs for lines containing a match or a text string.

grep command syntax

The syntax is:

grep "text string to search" directory-path

or

grep [option] "text string to search" directory-path

or

grep -r "text string to search" directory-path

or

grep -r -H "text string to search" directory-path

or

egrep -R "word-1|word-2" directory-path

or

egrep -w -R "word-1|word-2" directory-path

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.