在linux系统上找到所有匹配'name'的文件,并搜索'text' [英] Find all files matching 'name' on linux system, and search with them for 'text'

查看:193
本文介绍了在linux系统上找到所有匹配'name'的文件,并搜索'text'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在linux系统上查找'filename.ext'的所有实例,并查看哪些包含文本寻找。



是否有一组

 查找/ -type f -name文件名.ext -exec grep -l'lookingfor'{} + 

使用 + 终止命令比 \; 更有效率,因为 find 发送一个整体批处理文件到 grep ,而不是一个接一个地发送。这避免了对于找到的每个单个文件的fork / exec。



前面我做了一些测试来比较 xargs vs {} + vs {} \; > {} + 更快。以下是我的一些结果:

 时间查找。 -name* 20090430 *-exec touch {} + 
real 0m31.98s
用户0m0.06s
sys 0m0.49s

时间查找。 -name* 20090430 *| xargs touch
real 1m8.81s
用户0m0.13s
sys 0m1.07s

时间查找。 -name* 20090430 *-exec touch {} \;
real 1m42.53s
user 0m0.17s
sys 0m2.42s


I need to find all instances of 'filename.ext' on a linux system and see which ones contain the text 'lookingfor'.

Is there a set of linux command line operations that would work?

解决方案

find / -type f -name filename.ext -exec grep -l 'lookingfor' {} +

Using a + to terminate the command is more efficient than \; because find sends a whole batch of files to grep instead of sending them one by one. This avoids a fork/exec for each single file which is found.

A while ago I did some testing to compare the performance of xargs vs {} + vs {} \; and I found that {} + was faster. Here are some of my results:

time find . -name "*20090430*" -exec touch {} +
real    0m31.98s
user    0m0.06s
sys     0m0.49s

time find . -name "*20090430*" | xargs touch
real    1m8.81s
user    0m0.13s
sys     0m1.07s

time find . -name "*20090430*" -exec touch {} \;
real    1m42.53s
user    0m0.17s
sys     0m2.42s

这篇关于在linux系统上找到所有匹配'name'的文件,并搜索'text'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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