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

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

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

当前回答

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

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 -inr "Text" folder/to/be/searched/

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

grep -r <text_fo_find> <directory>

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

grep -ir <text_to_find> <directory>

A Simple find can work handy. alias it in your ~/.bashrc 文件:

alias ffind find / -type f | xargs grep

开始一个新的终端和问题:

ffind 'text-to-find-here'

所有以前的答案都建议抓住和找到,但还有另一种方式:使用中夜指挥官

它是一个免费的工具(30年,时间证明),它是视觉的没有GUI. 它有许多功能,找到文件只是其中之一。

使用:

grep -Erni + "text you wanna search"

命令将重复搜索当前目录的所有文件和目录,并打印结果。

注意:如果您的格雷普输出没有颜色,您可以通过在您的壳源文件中使用格雷普=‘格雷普=颜色=总是’的标志来更改它。