grep -r

Has anyone encountered a version of grep for freeBSD that works properly with wildcards recursively?In linux you can

Code:
grep -r "hello world" *.php

but in freeBSD it only works recursively with * by itself. I need this 10 times a day.
 
I've never used -r before, but I experienced the same on a quick test and short look at grep(1). It will only find the pattern in files in the current directory for me, too.
Anyway, if I where you I would use something like the following and create a shell alias for it, depending on your shell those would be a bit different.
Code:
% find . -type f -name "*php" -exec grep -H "hello world" {} +
./folder/file2.php:hello world
./file1.php:hello world
 
To list all *.php files that contains "search pattern" under the directory "/path/for/search/" use the following:
grep -rl --include="*.php" "search pattern" /path/for/search/

example:
grep -rl "function auth" --include="*.php" /usr/local/www/
 
I really just wanted -r to work the way it does in linux. I could write a program/script to do anything, but for some reason I just keep hoping that grep works.
 
Back
Top