查找包含多个字符串的文件 [英] Find files containing mutiple strings

查看:128
本文介绍了查找包含多个字符串的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用一个命令递归地查找包含特定 string1 的文件:

I use a command to recursively find files containing a certain string1:

find . -type f -exec grep -H string1 {} \;

我需要找到包含多个字符串的文件,因此该命令应返回包含所有字符串的文件。像这样:

I need to find files containing multiple strings, so the command should return those containing all strings. Something like this:

find . -type f -exec grep -H string1 AND string2 {} \;

我找不到方法。字符串可以在文件中的任何位置。即使是只有两个字符串的解决方案也不错。
您也可以试试这个;

I couldn't find a way. The strings can be anywhere in the files. Even a solution for only two strings would be nice.

推荐答案


find . -type f -exec grep -l 'string1' {} \; | xargs grep -l 'string2'

这显示了包含string1和string2的文件名

this shows file names that contain string1 and string2

这篇关于查找包含多个字符串的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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