How to use grep efficiently?

后端 未结 2 435
误落风尘
误落风尘 2020-12-07 09:53

I have a large number of small files to be searched. I have been looking for a good de-facto multi-threaded version of grep but could not find anything. How can

2条回答
  •  天命终不由人
    2020-12-07 10:23

    Wondering why -n1 is used below won't it be faster to use a higher value (say -n8? or leave it out so xargs will do the right thing)?

    xargs -0 -n1 -P8 grep -H "string"
    

    Seems it will be more efficient to give each grep that's forked to process on more than one file (I assume -n1 will give only one file name in argv for the grep) -- as I see it, we should be able to give the highest n possible on the system (based on argc/argv max length limitation). So the setup cost of bringing up a new grep process is not incurred more often.

提交回复
热议问题