Search query: list files containing a certain term

To get a list of files that contain a certain term for the current directory you can use this command to find the search query:

$> grep -lr SEARCHTERM

This shell command searches the current directory recursively (-r) and lists (-l) all files containing the search query SEARCHTERM. SEARCHTERM can also be a regular expression.

Example result:

$> grep --files-with-matches -lr 111-6676-344
481778223228.txt
475848816199.txt
730820777094.txt
810870348459.txt
914638096613.txt
1457194942179.txt
1305990982378.txt
167510767421.txt
787152968260.txt

If you want a list of findings of the search term with the corresponding file names, you can use the -H (or –with-filename) parameter or only use -r because its default if there is more than one file containing the searched term.

Example result:

$> grep -Hr 111-6676-344
481778223228.txt:#52 {main}";s:3:"url";s:37:"/catalogsearch/result/?q=111-6676-344";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:7:"default";}
475848816199.txt:#52 {main}";s:3:"url";s:37:"/catalogsearch/result/?q=111-6676-344";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:7:"default";}
730820777094.txt:#52 {main}";s:3:"url";s:37:"/catalogsearch/result/?q=111-6676-344";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:7:"default";}
810870348459.txt:#52 {main}";s:3:"url";s:37:"/catalogsearch/result/?q=111-6676-344";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:7:"default";}
914638096613.txt:#52 {main}";s:3:"url";s:37:"/catalogsearch/result/?q=111-6676-344";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:7:"default";}
1457194942179.txt:#52 {main}";s:3:"url";s:37:"/catalogsearch/result/?q=111-6676-344";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:7:"default";}
1305990982378.txt:#52 {main}";s:3:"url";s:37:"/catalogsearch/result/?q=111-6676-344";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:7:"default";}
167510767421.txt:#52 {main}";s:3:"url";s:37:"/catalogsearch/result/?q=111-6676-344";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:7:"default";}
787152968260.txt:#52 {main}";s:3:"url";s:37:"/catalogsearch/result/?q=111-6676-344";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:7:"default";}

Additional information to grep search query’s:

Leave a Reply

Your email address will not be published.

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.