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

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

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

当前回答

grep "text-to-find-here" file_name

grep "text-to-find-here" directory_path/*

如果你想搜索当前的目录:

grep "text-to-find-here" *

其他回答

find /path -type f -exec grep -l "string" {} \;

评论的解释

查找是一个命令,允许您在特定路径的子目录中找到文件和其他对象,如目录和链接,如果您不指定该文件名称应满足的面具,则列出所有目录对象。

-type f specifies that it should proceed only files, not directories etc.
-exec grep specifies that for every found file, it should run grep command, passing its filename as an argument to it, by replacing {} with the filename

下面的命令将为此做得很好:

find ./ -name "file_pattern_name"  -exec grep -r "pattern" {} \;

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/

屏幕射击:

此分類上一篇

有一个Ack工具,它会做你正在寻找的东西:

ack -i search_string folder_path/*

您可能会忽略 -i 对案例敏感搜索。

您可以使用 ripgrep 将遵守默认项目的.gitignore 文件。

此分類上一篇

拒绝许可的错误:

rg -i rustacean 2> /dev/null

将默认错误(stderr)输出转向 /dev/null。