# grep -r



## Barney (Nov 5, 2019)

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


```
grep -r "hello world" *.php
```

but in freeBSD it only works recursively with * by itself. I need this 10 times a day.


----------



## shkhln (Nov 5, 2019)

Wildcards are interpreted by the shell. Also, `grep` _is_ GNU grep (with some features disabled).


----------



## sand_man (Nov 6, 2019)

shkhln said:


> `grep` _is_ GNU grep (with some features disabled).


Are you sure? The source has a BSD license





__





						[base] Contents of /release/12.1.0/usr.bin/grep/grep.c
					






					svnweb.freebsd.org
				




```
/*-
6     * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
7     *
8     * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
9     * Copyright (C) 2008-2009 Gabor Kovesdan <gabor@FreeBSD.org>
10     * All rights reserved.
```


----------



## shkhln (Nov 6, 2019)

https://github.com/freebsd/freebsd/tree/master/gnu/usr.bin/grep



sand_man said:


> Are you sure? The source has a BSD license
> 
> 
> 
> ...



That's `bsdgrep`, I believe.


----------



## k.jacker (Nov 6, 2019)

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.

```
% find . -type f -name "*php" -exec grep -H "hello world" {} +
./folder/file2.php:hello world
./file1.php:hello world
```


----------



## VladiBG (Nov 6, 2019)

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/`


----------



## Barney (Nov 6, 2019)

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.


----------



## shkhln (Nov 6, 2019)

Barney said:


> I really just wanted -r to work the way it does in linux.



Well, then you are in luck because it works exactly as in Linux.


----------



## sand_man (Nov 6, 2019)

shkhln said:


> That's `bsdgrep`, I believe.



Sorry, I misunderstood the original request.


----------



## SirDice (Nov 7, 2019)

Barney said:


> I really just wanted -r to work the way it does in linux.


textproc/gnugrep

Why is FreeBSD not (more) like ....


----------

