I've got a number of .conf files in the following "lxadmin" directory and suspect that the text "tanguay.info" is in one of them somewhere.

I do this command:

cat /etc/httpd/conf/lxadmin/* | grep "tanguay.info"

And it tells me:

cat: /etc/httpd/conf/lxadmin/forward: Is a directory
Include /home/httpd/tanguay.info/conf/lxadmin.tanguay.info

So I know that it is in there somewhere, but it doesn't tell me in which file.

How can I get it to also tell me in which file the text is located?

  • 4
    This is a classic useless usage of cat. In 99% of cases you do not need to use cat, as the command you're piping to will take a filename or a list of files. partmaps.org/era/unix/award.html will show you some examples of how to write your commands better. Jul 5, 2009 at 8:14

9 Answers 9


grep "tanguay.info" /etc/httpd/conf/lxadmin/*, as long as the file is not in a subdirectory.


If there are subdirectories you can use

rgrep "tanguay.info" /etc/httpd/conf/lxadmin/


grep -r "tanguay.info" /etc/httpd/conf/lxadmin/


You can also use ack, an enhanced grep written in perl (no deps required on standalone version). ack searches recursively through directories by default.

ack "tanguay.info" /etc/httpd/conf/lxadmin/

On Ubuntu, you can find it in the ack-grep package.

  • 1
    If grep is given more than one file to search, or you use the recursive search, it will print out the name of matching file at the start of the line. Jul 5, 2009 at 8:11
  • +1 for recommending Ack. After all, it's betterthangrep.com
    – Telemachus
    Jul 5, 2009 at 21:34

What you are looking for is option -H of grep which shows the matching filename together with the match. You can also add -r to search a directory recursively. I.e.

$ grep -r -H "tanguay.info" /etc/httpd/conf/lxadmin/


find . | xargs grep 'string' -sl

The -s is for summary and won't display warning messages such as grep: ./directory-name: Is a directory

The -l is for list, so we get just the filename and not all instances of the match displayed in the results.

  • 4
    -1 First of all, never use find and xargs without using -print0 with find and -0 with xargs, or files with spaces will cause you problems. Secondly, you've just reimplemented "grep -r", badly. Thirdly, -s is "suppress error messages", not "summary" Jul 5, 2009 at 8:09
# cd /directory/of/files/
# grep -A 5 -B 5 'keywords' *

show 5 lines before and 3 lines after so that you can see the context of the keywords

makes all the difference in understanding how the keywords are used in the file

grep -Rl "tanguay.info" /etc/httpd/conf/lxadmin/

On windows systems:

type *.* | find "<string>"

The quotes must be in there, by the way.


You can use backquote to find only in files. [ ` -> key left to Number 1 key above to Tab key]

grep -wn "tanguay.info" find /etc/httpd/conf/lxadmin/ -iname "*.conf"

The above code will first get the *.conf files and then search the "tanguay.info" among the result.

Run the above command in a super user login to avoid permission problems.


The solition below is very similar to Izzy's response above but offers a little more flexibility. I find it very useful when I need to do a little more than xargs will allow (especially on older SunOS systems where grep -r or rgrep is not available)

find . -name "*.conf" -exec grep -l tanguay.info {} \;

Quite simply, you are finding all the *.conf files and executing a grep on each result that is found. The \; completes the -exec portion of the command.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .