Finding files in Linux that contain a text string
Posted on 2013-08-29
This seems like such a simple task, but I haven't found a simple, fast way to do this in Linux. How can I find the file name in a particular directory that contains a particular word (or text string) when I don't know the file name? (I usually do know the file extension.)
For example, recently I needed to find the file that contained the word "indexfile". I knew the directory it was in, and I knew that the file extension was "ctl". This command was very fast, and it confirmed that the file was there somewhere, but it didn't give me the file name:
$ cat *.ctl | grep indexfile
That quickly returned this:
What Linux command can I use to search the *.ctl files in my current directory and give me the name of the file that contains this search string? If that command can also return the line of text and/or the line number in the file that would also be helpful.