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 :-)
The
41
needs to be in the file name, or its content? – Daniel Beck – 2011-05-31T06:51:38.350@Daniel In the contents, sorry if it wasn't clear. – alex – 2011-05-31T06:53:40.543
it does that because you told it to only search all files ending in php in the CWD - mind the expansion precedence... – Florenz Kley – 2013-01-31T01:00:13.453