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

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

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/

屏幕射击:

此分類上一篇

其他回答

您可以使用 ack. 它就像输入源代码. 您可以扫描您的整个文件系统。

只是做:

ack 'text-to-find-here'

在你的根目录中。

您也可以使用常规表达式,指定文件类型等。


更新

我刚刚发现The Silver Searcher,这类似于Ack,但比它快3至5倍,甚至忽略了来自.gitignore 文件的模式。

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

ack -i search_string folder_path/*

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

使用 pwd 从您所在的任何目录中搜索,向下滑动

grep -rnw `pwd` -e "pattern"

取决于您正在使用的 grep 版本,您可以忽略 pwd. 在更新的版本中,如果没有目录,则似乎是 grep 的默认情况。

这样:

格雷普 -rnw -e “模式”

格雷普 -rnw “模式”

他们会像上面那样做!

我很感动如何简单的吸引力使它与“rl”:

grep -rl 'pattern_to_find' /path/where/to/find

-r to recursively find a file / directory inside directories..
-l to list files matching the 'pattern'

使用“r”而不“l”以查看文件名跟随文本中的模式!

grep -r 'pattern_to_find' /path/where/to/find

它只是完美工作......

您可以使用以下命令从文件中找到特定文本:

cat file | grep 'abc' | cut -d':' -f2