我如何并行grep [英] How do I grep in parallel

查看:16
本文介绍了我如何并行grep的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常使用 grep -rIn pattern_str big_source_code_dir 来查找一些东西.但是 grep 不是并行的,我如何使它并行?我的系统有 4 个内核,如果 grep 可以使用所有内核,它会更快.

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.

推荐答案

如果您使用 HDD 来存储您正在搜索的目录,速度不会提高.硬盘驱动器几乎是单线程访问单元.

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.

但是如果你真的想做并行grep,那么本网站 给出了如何使用 findxargs 进行操作的两个提示.例如

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

这篇关于我如何并行grep的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆