Cygwin 'grep' in files takes forever

1

1

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.

IAdapter

Posted 2011-12-05T15:03:01.470

Reputation: 669

Try grep -rne word * This * should not be necessary, but it work for me – None – 2011-12-05T16:55:12.207

Answers

5

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 .

(Note 2012-07: The latest version of GNU grep will search the current directory automatically if -r is given.)


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.

user1686

Posted 2011-12-05T15:03:01.470

Reputation: 283 655

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 – 2011-12-05T19:26:15.007

1Be 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 – 2011-12-05T19:28:02.023

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). – user1686 – 2011-12-05T19:56:44.287

@grawity Yep, the Cygwin DLL does that if a Cygwin program is invoked from outside Cygwin. – ak2 – 2011-12-05T20:20:02.123