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

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

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

当前回答

这个捕捉命令会给你一个准确的结果,当你正在寻找特定的文本在Linux -

grep -inRsH “文本要被搜索” /path/to/dir(它可以是“。

i stands for ignore case distinctions R stands for recursive and it also includes symlinks. It is better to use 'R' instead of 'r' n stands for "it will print line number." s stands for "suppress error messages" H stands for "it will print the file name for each match"

其他回答

使用 grep -ilR:

grep -Ril "text-to-find-here" /

i 代表忽略案例(可选在您的案例中)。R 代表重复。l 代表“显示文件名,而不是结果本身”。 / 代表在您的机器的根源开始。

此外,请参见 The Platinium Searcher,这类似于 The Silver Searcher,并写在 Go。

例子:

pt -e 'text to search'

使用:

grep -c Your_Pattern *

这将报告您的模式在当前目录中的每个文件中有多少副本。

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

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

如果您在 Git 存储库中,您可以使用:

git grep something