Friday, June 12, 2009

Searching Text in Files (Unix/Linux)

I was looking for a way to find files in a directory which contain specific text.
The results should be only the name of the files, not the lines in the files that contain the text.
(That is the way grep normally do.)

The solution is very simple:

grep -i -r -l "text"

where
-i = ignore case (up to you though),
-r = search recursively through sub-directories,
-l = returns only the file names, not the line contents.
and indeed, text has to be replaced with your text but the quotation marks have to be intact.

No comments: