Find | grep doesn’t work in Cygwin

cygwin;findgrep

I have cygwin installed and when I search for the source code with this command nothing show up, even that I have that string in a file

$ echo foo > bar
$ find . -name '*' | grep foo

Nothing shows up. This command works fine on GNU+Linux.

$ grep foo bar

Best Answer

As mentioned, find outputs a list of found files to stdout, grep normally expects to search through stdout if called this way.

Could also pipe find to xargs, and it will "build and execute command lines from standard input", as in

$ find . | xargs grep foo

If you have crazy filenames, with newlines and whatnot, then this would be better:

$ find . -type f -print0 | xargs -0 grep foo

and the -type f will only find regular files, so no attempts to grep through any . or .. or any directories or "funny" files.

Related Question