How do I grep in parallel

grep, linux

Solution

There will not be speed improvement if you are using a HDD to store that directory you are searching in. Hard drives are pretty much single-threaded access units.

But if you really want to do parallel grep, then this website gives two hints of how to do it with `find` and `xargs`. E.g.

find . -type f -print0 | xargs -0 -P 4 -n 40 grep -i foobar

Problem

I usually use `grep -rIn pattern_str big_source_code_dir` to find some thing. but the `grep` is not parallel, how do I make it parallel? My system has 4 cores, if the `grep` can use all the cores, it would be faster.

Original source