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

Written by Ian Carnaghan · 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.


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
Written by Ian Carnaghan
I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment. Profile

Leave a Reply

Notify of