Command-Line Grep – Params to Return Only File Names

command linegrep

I'm trying to use grep to find a specific piece of text in a bunch of files on my web server. No problem, except that it returns way more information than I want! Ideally it would just return a list of files, and if the text exists in more than one place in the file it would only list the file name once.

Currently I'm using something like this:

grep -ir essay_ "mysite"

to do a case-insensitive recursive search for the word essay_ in all directories of my site. What it returns is something like this:

mysite/dot/contest_declaration.php:$questions = $db->get_results("SELECT * FROM dot_essay WHERE active = 1 order by display_order asc");
mysite/dot/contest_declaration.php:     $db->query("DELETE FROM dot_essay_xref WHERE entry_id = $svar_entry_id");
mysite/dot/contest_declaration.php:     $id = $question->essay_id;
mysite/dot/contest_declaration.php:     $answer = ${"essay_$id"};
shoppermarketexpo/dot/print_declaration.php:        $questions = $db->get_results("SELECT * FROM dot_essay WHERE active = 1");

What I'd like to get back is:

mysite/dot/contest_declaration.php
mysite/dot/print_declaration.php

Best Answer

   -l, --files-with-matches
          Suppress normal output; instead print the  name  of  each  input
          file  from  which  output would normally have been printed.  The
          scanning will stop on the first  match.   (-l  is  specified  by
          POSIX.)

from grep manpage

Related Question