Saturday, March 8, 2008

Search for a string in a list of files with grep/bash

Today I was trying to find which file the main() function was in, in a source code directory for a project that I'm looking at. To do this, you would do the following: and that's it

$> grep -lir "main" *

and that's it. So just call grep with -lir and the search string you're looking for, and in the files you're interested in (all files in the current directory in my case). The grep params are:

-l: outputs on the file name where the string occured
-i: ignore the case
-r: recursively look into all directories

Damn I love grep...

No comments:

Post a Comment