我如何在其文件内容中找到包含一个特定的文本序列的所有文件?

下一个不起作用. 它似乎显示系统中的每个单一文件。

find / -type f -exec grep -H 'text-to-find-here' {} \;

当前回答

我尝试了下面的捕捉命令,它有助于在 /etc/yum.repos.d 我的存储库中搜索内容。

grep -Ril -e 'texttoSearch' /etc/yum.repos.d

其他回答

包含特定文本的文件名列表

首先,我相信你使用了 -H 而不是 -l. 你也可以尝试在引用中添加文本,其次是 {} \。

find / -type f -exec grep -l "text-to-find-here" {} \; 

例子

假设您正在寻找包含特定文本“Apache 许可证”的文件在您的目录中,它将显示一些类似于下面的结果(结果将根据您的目录内容不同)。

bash-4.1$ find . -type f -exec grep -l "Apache License" {} \; 
./net/java/jvnet-parent/5/jvnet-parent-5.pom
./commons-cli/commons-cli/1.3.1/commons-cli-1.3.1.pom
./io/swagger/swagger-project/1.5.10/swagger-project-1.5.10.pom
./io/netty/netty-transport/4.1.7.Final/netty-transport-4.1.7.Final.pom
./commons-codec/commons-codec/1.9/commons-codec-1.9.pom
./commons-io/commons-io/2.4/commons-io-2.4.pom
bash-4.1$ 

取消案例敏感性

即使你不使用案例如“文本”与“文本”,你可以使用 -i 交换来忽略案例。

下面是可以用于搜索文件的几个命令列表。

grep "text string to search” directory-path

grep [option] "text string to search” directory-path

grep -r "text string to search” directory-path

grep -r -H "text string to search” directory-path

egrep -R "word-1|word-2” directory-path

egrep -w -R "word-1|word-2” directory-path

安德鲁·加兰特的博客声称:“Ripgrep 比 {grep, ag, git grep, ucg, pt, sift} 更快”(一些人分享的声明,这就是为什么一个功能比较是有用的)。 特别有兴趣的是他关于 regex 实施和漏洞的部分. 下一个命令搜索所有文件,包括隐藏和可执行: $ rg -uuu foobar 银搜索器(ag)声称它是 5-10 倍的速度。

虽然可以扫描外部程序,执行搜索,阻止其输出并处理它,呼叫API是电源和性能的途径。

试试:

find / -type f -exec grep -H 'text-to-find-here' {} \;

将搜索所有文件系统,因为 / 是根文件夹。

Home 文件夹使用:

find ~/ -type f -exec grep -H 'text-to-find-here' {} \;

目前使用文件夹:

find ./ -type f -exec grep -H 'text-to-find-here' {} \;

GUI Search Alternative - 用于桌面使用:

因为问题不准确要求命令。

Searchmonkey: Advanced file search tool without having to index your system using regular expressions. 图形相当于查找/查找. 可用于 Linux (Gnome/KDE/Java) 和 Windows (Java) - 开源 GPL v3

特性:

Advanced Regular Expressions Results shown in-context Search containing text Panel to display line containing text 新 2018 更新等。

下载 - 链接:

主页: http://searchmonkey.embeddediq.com/ 下载: http://searchmonkey.embeddediq.com/index.php/download-latest Repo: https://sourceforge.net/projects/searchmonkey/files/

屏幕射击:

此分類上一篇