0

So I have a directory with ~50 files, and each contain different things. I often find myself not remembering which files contain what. (This is not a problem with the naming -- it is sort of like having a list of programs and not remembering which files contain conditionals).

Anyways, so far, I've been using

cat * | grep "desiredString"

for a string that I know is in there. However, this just gives me the lines which contain the desired string. This is usually enough, but I'd like it to give me the file names instead, if at all possible.

How could I go about doing this?

James
  • 2,635
  • 5
  • 23
  • 30
  • possible duplicate of [Finding all files containing a text string on Linux](http://stackoverflow.com/questions/16956810/finding-all-files-containing-a-text-string-on-linux) – Reinstate Monica Please Jul 17 '14 at 23:50

2 Answers2

1

It sounds like you want grep -l, which will list the files that contain a particular string. You can also just pass the filename arguments directly to grep and skip cat.

grep -l "desiredString" *
merlin2011
  • 71,677
  • 44
  • 195
  • 329
  • Hm - I just tried that and Bash returned `(standard input)` Do I need to configure anything for this to work? – James Jul 17 '14 at 23:38
0

In the directory containing the files among which you want to search:

grep -rn "desiredString" .

This can list all the files matching "desiredString", with file names, matching lines and line numbers.

nicky_zs
  • 3,633
  • 1
  • 18
  • 26