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

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

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

当前回答

格雷普是你的好朋友来实现这一点。

grep -r <text_fo_find> <directory>

如果你不在乎要找到文本的案例,那么使用:

grep -ir <text_to_find> <directory>

其他回答

如果您的捕捉不支持重复搜索,您可以将搜索与 xargs 相结合:

find / -type f | xargs grep 'text-to-find-here'

我觉得这比找到 -exec 的格式更容易记住。

这将产生相匹配线的文件名和内容,例如。

/home/rob/file:text-to-find-here

您可能想添加到捕捉的选项旗帜:

-i - 案例不敏感搜索 -l - 只输出相匹配的行输出(而不是相匹配的行输出)

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/

屏幕射击:

此分類上一篇

你的命令是正确的. 你只需要添加 -l 来抓住:

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

试试:

find . -name "*.txt" | xargs grep -i "text_pattern"
grep -lrnw '/root/Desktop/ipozal' -e 'geolocation'

例如:

我的文件夹名称是“Ipozal”它放在“/root/Desktop”我想在所有文件中找到此文本“地理位置”