There are times you need to search for a particular string or pattern in multiple text files. This is when grep proves to be a really handy tool. Type:
# grep -rsniH search_term *
The options mean:
r - be recursive
s - suppress any error messages
n - print the line number
i - do a case insensitve search
H - print the filename
Here are some examples:
# grep -rsniH "hello" * # egrep -rsniH "^the.*http:" *
The first searches all text files for the word “hello“. The second one searches for lines that begin with “the” and also contain “http:“.
You should check the grep man page for more info.
Search for a string in multiple files by George Notaras is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Copyright © 2005 - Some Rights Reserved