Leg*_*end 40 unix linux search grep text
我有大量的小文件要搜索.我一直在寻找一个好的事实上的多线程版本,grep但找不到任何东西.如何提高我对grep的使用?截至目前我这样做:
grep -R "string" >> Strings
Run Code Online (Sandbox Code Playgroud)
Leg*_*end 80
如果您在多核处理器上安装了xargs,那么只要有人感兴趣,您就可以从以下方面受益.
环境:
Processor: Dual Quad-core 2.4GHz
Memory: 32 GB
Number of files: 584450
Total Size: ~ 35 GB
Run Code Online (Sandbox Code Playgroud)
测试:
1.找到必要的文件,将它们传递给xargs并告诉它执行8个实例.
time find ./ -name "*.ext" -print0 | xargs -0 -n1 -P8 grep -H "string" >> Strings_find8
real 3m24.358s
user 1m27.654s
sys 9m40.316s
Run Code Online (Sandbox Code Playgroud)
2.找到必要的文件,将它们传递给xargs并告诉它执行4个实例.
time find ./ -name "*.ext" -print0 | xargs -0 -n1 -P4 grep -H "string" >> Strings
real 16m3.051s
user 0m56.012s
sys 8m42.540s
Run Code Online (Sandbox Code Playgroud)
3.由@Stephen建议:找到必要的文件并使用+而不是xargs
time find ./ -name "*.ext" -exec grep -H "string" {} \+ >> Strings
real 53m45.438s
user 0m5.829s
sys 0m40.778s
Run Code Online (Sandbox Code Playgroud)
4.常规递归grep.
grep -R "string" >> Strings
real 235m12.823s
user 38m57.763s
sys 38m8.301s
Run Code Online (Sandbox Code Playgroud)
为了我的目的,第一个命令工作正常.
| 归档时间: |
|
| 查看次数: |
22268 次 |
| 最近记录: |