[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: grep -r doesn't work in Cygwin

From: Julian Foad
Subject: Re: grep -r doesn't work in Cygwin
Date: Wed, 29 Apr 2009 09:51:17 +0000 (GMT)

Chloe wrote:
> Files in subdirectories are not being searched. See example
> below. TableDictionary.php is not found.
> $ grep -r bugs *.php
> soap.php:     $bugs = $contact->get_linked_beans('bugs','Bug');

You misunderstand this syntax. It doesn't mean "look in all directories under 
'.', searching only in files that match '*.php' in each one."

Instead, "-r" means "If a file you specified is a directory, search all the 
files inside it (recursively)." The files you specified are the result of the 
shell expanding '*.php' in the CURRENT directory, so grep sees your command as 
something like "grep -r bugs soap.php other.php".

(Unlike Unix-like shells, the native Windows shell ("command prompt") doesn't 
expand wildcards but just passes them to the application, so applications more 
often behave the way you were expecting.)

So there are two things you need to do: tell grep a directory (e.g. ".") or 
some directories (e.g. "*/") to search in; and tell grep to look only in files 
matching '*.php' in each one. You can do it like this:

grep -r bugs --include '*.php' .

Note the quotes around "*.php" which prevent the shell from expanding it to a 
list of files.

- Julian

reply via email to

[Prev in Thread] Current Thread [Next in Thread]