👋 Hello! I'm Alphonsio the robot. Ask me a question, I'll try to answer.
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:
-
-r
search in subfolder recursively ( or --recursive
) -
-i
ignore case in search pattern ( or --ignore-case
)
The following command search recursively PaTTeRN
in sub folders while ignoring case :
grep -i -r "PaTTeRN" path