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

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

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

当前回答

您可以使用下面的命令,因为您不想要文件名,但您想要从所有文件中搜索。

grep -e TEXT *.log | cut -d' ' --complement -s -f1

捕捉与 -e 选项是相当快的与其他选项相比,因为它是PATTERN 比赛

其他回答

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

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

避免混乱并安装 ack-grep. 它消除了许多许可和引用问题。

apt-get install ack-grep

然后转到您想要搜索的目录,并运行下面的命令。

cd /
ack-grep "find my keyword"

使用:

grep -c Your_Pattern *

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

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

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

使用 grep -ilR:

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

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