Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Spawning a separate grep for each file? That's terribly inefficient. At least use xargs which will run one process on as many files as possible.

But you know there's a -r for recursive, right? And unless you are using some historic relic of grep that is not GNU or BSD and doesn't understand the --include option you can just do:

grep -rin "needle" --include "*.foo" .



I use something along the lines of

    find . -iname '.*' -prune -o -iname '*.foo' -exec grep needle {} +
I don't want to have to learn 10 different command syntaxes for walking directory trees, so find works well. The "+" terminator of find's exec is similar to xargs, but preserves the flexibility of find's exec.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: