in order for grep to work recursively, the argument to grep needs to include the directories it's expected to recurse.
looking at the following files
shiny:t fl$ find .
.
./evenmore
./evenmore/foo.php
./evenmore/inhere.php
./evenmore/no41in.php
./foo.php
./inhere.php
./morestuff
./morestuff/foo.php
./morestuff/inhere.php
./morestuff/no41in.php
./no41in.php
./stuff
./stuff/no41in.php
this does not work:
shiny:t fl$ grep -r 41 *.php
foo.php:41
inhere.php:41
because after path name expansion is done, the shell has processed the asterisk and the command line is now
shiny:t fl$ set -x
shiny:t fl$ grep -r 41 *.php
+ grep -r 41 foo.php inhere.php no41in.php
foo.php:41
inhere.php:41
there is no directory to descend in in the argument handed to grep. This however will descend in all directories present:
shiny:t fl$ grep -r 41 .
./evenmore/foo.php:41
./evenmore/inhere.php:41
./foo.php:41
./inhere.php:41
./morestuff/foo.php:41
./morestuff/inhere.php:41
whether that also processes dot-directories is left as an exercise to the reader :-)
41needs to be in the file name, or its content? – Daniel Beck♦ May 31 '11 at 6:51