How do I find all files containing specific text on Linux

  • Posted on: 4 May 2018
  • By: jmu

This command will help us find all files which contain specific text on Linux:

grep -rnl "/var/path/samplefolder" -e "sampletext"

If you would like to know what that line looks like and get the line number, use the following command:

grep -rnw "/var/path/samplefolder" -e "sampletext"

-r is recursive

-n is line number

-l (lowercase L) returns the file name which contains the text you need 

-w gives the line which contains the whole matching word

 

Reference: Find all files containing specific text on Linux

Tags: 

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.