问题描述
这个问题与如何高效使用grep?
我正在尝试在一个文件夹中搜索字符串",该文件夹包含 8-1000 万个小型(~2-3kb)纯文本文件.我需要知道所有带有字符串"的文件.
I am trying to search for a "string" in a folder which has 8-10 million small (~2-3kb) plain text files. I need to know all the files which has "string".
一开始我用过这个
grep "string"
那太慢了.
然后我尝试了
grep * "string" {} ; -print
基于链接的问题,我使用了这个
Based on linked question, I used this
find . | xargs -0 -n1 -P8 grep -H "string"
我收到此错误:
xargs: argument line too long
有没有人知道一种相对更快地完成这项任务的方法?
Does anyone know a way to accomplish this task relatively quicker?
我在具有超过 50GB 可用 RAM 和 14 个 CPU 内核的服务器机器上运行此搜索.我希望能以某种方式利用所有处理能力更快地运行此搜索.
I run this search on a server machine which has more than 50GB of available RAM, and 14 cores of CPU. I wish somehow I could use all that processing power to run this search faster.
推荐答案
You should remove -0
argument to xargs
and up -n
参数代替:
You should remove -0
argument to xargs
and up -n
parameter instead:
... | xargs -n16 ...
这篇关于如何使用具有大量(数百万)个文件的 grep 搜索字符串并在几分钟内获得结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!