How to search file for text in Linux

Name grep comes from “globally search for a regular expression and print matching lines

For search “my text” in current directory (“./”) use next command line:

# grep -irnsw ./ -e 'my text'

Where each option is for:

-i – ignore case

-n – display line number where match was found

-r – recursive, loop through all files under each directory

-s – suppress error messages (like when unable to open file)

-w – matching whole words only

For searching only in certain type of files, you can use --inlude selection:

# grep -rn ./ --include \*.log -e 'find my text'

@source: https://en.wikibooks.org/wiki/Grep

Leave a Reply