How to search a given pattern (word or 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:
grep "pattern to search" path
For example, the following command find all files in the current folder containing the string text to find:
grep "text to find" *.*
The following options may also be helpful:
-
-rsearch in subfolder recursively ( or --recursive) -
-iignore case in search pattern ( or --ignore-case)
The following command search recursively PaTTeRN in sub folders while ignoring case :
grep -i -r "PaTTeRN" path
The grep command can be used to find a word or a text (called pattern) in files under Linux:
grep "pattern to search" path
For example, the following command find all files in the current folder containing the string text to find:
grep "text to find" *.*
The following options may also be helpful:
-
-rsearch in subfolder recursively ( or --recursive) -
-iignore case in search pattern ( or --ignore-case)
The following command search recursively PaTTeRN in sub folders while ignoring case :
grep -i -r "PaTTeRN" path
| # | ID | Query | URL | Count |
|---|