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

H

How Can We Help?

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

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.

About the author

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.

About Author

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.

Follow Me