[SLUG] Pah, that Allsopp

Ross Kendall ross at rosskendall.com
Wed Nov 14 21:37:14 GMT 2007


Hi John, not sure about all your questions, but I've put a couple of
comments below.

John Allsopp wrote:
> > John Allsopp wrote:
> >> Why doesn't
> >> grep -ir "models" *php*
> >>
> >> find matches in subdirectories on my machine
>
> Ross Kendall wrote:
>> I would use find and grep together to do what you want:
>> find ./ -name *php* -type f -exec grep -i "models" '{}' \;
>
> Thanks Ross. I had to quote '*php*' to get it to work, but I couldn't
> get -type f to work (it worked OK without).
>
> Anyone any idea why?
The string after -name is a shell pattern, so it's behavior is
determined by the shell not the find command (I use bash v3.2.25 on
openSUSE, and it works without the quotes, but it could be a bash config
setting)  Anyway, using quotes is a good idea anyway, although maybe
double quotes would be more appropriate.

The find option: -type f  (regular file) should work, but check the
'find' man page on your system in case there is something different
>
> I got
> Find: paths must precede expression
>
> which is the error I got from not quoting *php*
>
> I tried putting -name -type f
> I was testing find ./ -name '*php*' -type f
>
> Also, what does that / in ./ give us? It worked with ., so I just
> wondered why it was there.
That's just a habit of mine.  Both . and ./ refer to the current
directory.  (I probably picked up the habit on some old unix system that
needed ./)

so, a revised command:
find . -name "*php*" -type f -exec grep -i "models" '{}' \;
>
> Cheers
> J
>




More information about the Scarborough mailing list