I tried using Cygwin to emulate some cool Linux search feature, and when I do grep in files (12 text files - not big) it takes forever. I used

grep -rne word

I could find this word faster manually (even without Ctrl + F). Is there any reason this does not work? How to fix it?

P.S.: I use the Cygwin console.

link|improve this question

Try grep -rne word * This * should not be necessary, but it work for me – mbair Dec 5 '11 at 16:55
feedback

1 Answer

up vote 2 down vote accepted

You forgot to tell grep where to search, so it just sits there waiting for data to be input from 'stdin' – often a pipe, but in this case your keyboard. You can confirm by entering something like "this is a word", Enter, CtrlZ, Enter.

If you want to search the current directory, recursively, give . as the path.

grep -rne word .

In many cases, * will work too, but it is not recommended because 1) it is inefficient – expanding the wildcard to all file names takes some time and might even overflow the permitted command line length; 2) it does not match dotfiles (names starting with a dot) in most shells, although I'm not sure if this applies to expansion done by Cygwin itself.

link|improve this answer
Expansion of wildcards is handled by the shell, and Cygwin uses bash by default. It works the same way as on Linux or Unix systems. – Keith Thompson Dec 5 '11 at 19:26
1  
Be careful. grep -rne word . > grep.out will include grep.out in the files being searched, and will run until you run out of disk space. – Keith Thompson Dec 5 '11 at 19:28
1  
@Keith: Cygwin programs can be run from cmd.exe and PowerShell as well, in which case the expansion has to be done by the program itself (or by the Cygwin runtime). – grawity Dec 5 '11 at 19:56
@grawity Yep, the Cygwin DLL does that if a Cygwin program is invoked from outside Cygwin. – ak2 Dec 5 '11 at 20:20
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.