Question #192   Submitted by Answiki on 11/12/2020 at 06:26:55 PM UTC

How to search a given pattern (word or string) in files in command line under Linux?

Answer   Submitted by Answiki on 11/12/2020 at 06:36:09 PM UTC

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

2 events in history
Answer by Answiki on 11/12/2020 at 06:36:09 PM

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

Question by Answiki 11/12/2020 at 06:26:55 PM
How to search a given pattern (word or string) in files in command line under Linux?
# ID Query URL Count

Icons proudly provided by Friconix.