Finding pattern (word or text string) in files in command line under Linux

The grep command can be used to find a word or a text (called pattern) in files under Linux or Ubuntu:

grep "pattern to search" path/

For example, one can looking for the word ‘text’ in the current folder with the following command:

grep text *.*

Looking in sub-folders with -r option:

grep -r "pattern" path

-i option ignores case in search pattern:

grep -i "PaTTeRN" path

Leave a Reply

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