Linux How to find content in files

The grep command search the content of all the files in a directory.

Run the following command:


grep -inR TOFIND

The i parameter is for case insensitive, n displays the line number and the R parameter is for recursive.

Example:

This example search all the files in the current directory and all the sub directories for the value test.


$ grep -inR test
dir/file3.txt:1:test
file1.txt:4:test
file1.txt:7:this is a test
file2.txt:4:test
file2.txt:7:this is a test
file2.txt:11:test
file2.txt:14:this is a test


The output returns the file name, then the line number where the value was found and finally the value matched. File3.txt from the subdirectory dir contains test on line 4. File2.txt contains 4 instances of the value test.

References:

Grep command

Recent Comments