How to search for certain text/information within files using Linux

28 sec read

Example: If you have a directory with 10 000 text files in it and you need to find a certain word in a certain file but you aren’t sure what the name of the file is. You can use the method described below to find the file with selected text within it.

Answer:

In the command line type the following command: grep -rni “Hello World” *.txt and press enter to execute the command. What this command does it searches within all the txt (text) files to find the sentence “Hello World” and list the results.

Parameter Explanation:

-r : (–recursive) Read all  files  under  each  directory  recursively.
-n : (–line-number)  Prefix  each  line of output with the 1-based line number within its input file.
-i : (–ignore-case) Ignore  case  distinctions  in  both  the  PATTERN and the input files.

Last Updated On April 07, 2018

Leave a Reply

avatar
  Subscribe  
Notify of