Sunday, November 21, 2010 

Using Grep to search in files

grep -inIEr --color=ALWAYS -C1  --include="*.php" "Foo.*=" source/code/directory/

"i" means that the search is going to be case-insensitive.
"n" asks the tool to print the line number next to each match
"I" means grep uses some impressive guesswork to figure out which files are binary not text, and skips matching those
"E" tells the tool to treat the pattern as a Posix extended regular expression, since the default of basic is very limited in what you can express.
"r" prepares the tool to look at all the files and sub-folders within the main directory you specify
--color option causes the matched parts of the result lines to be highlighted in color
-C1 means print 1 line above and below the matched line
--include option makes grep look in files only ending in the pattern provided.

Found this really impressive snippet here  Linux command line rocks :)