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

No Comments

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.

Image Credits: Photo by Isis França on Unsplash.

Related Articles

No results found

Leave a Reply

avatar
  Subscribe  
Notify of
Menu
Copy link