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

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

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

当前回答

试试:

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

将搜索所有文件系统,因为 / 是根文件夹。

Home 文件夹使用:

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

目前使用文件夹:

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

其他回答

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

grep -rnw `pwd` -e "pattern"

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

这样:

格雷普 -rnw -e “模式”

格雷普 -rnw “模式”

他们会像上面那样做!

使用 grep -ilR:

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

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

我很感动如何简单的吸引力使它与“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

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

如果你有一组文件,你会一直在检查,你可以列出他们的路径,例如:

alias fd='find . -type f -regex ".*\.\(inc\|info\|module\|php\|test\|install\|uninstall\)"'

然后你可以简单地过滤列表如下:

grep -U -l $'\015' $(fd)

将列表 fd 过滤到包含 CR 模式的文件。

我发现,将我感兴趣的文件会帮助我创建更容易的脚本,然后总是试图记住如何获得所有这些文件。 回复的物品工作,但早或晚你将不得不争取分散特定的文件类型。

试试这

find . -type f -name some_file_name.xml -exec grep -H PUT_YOUR_STRING_HERE {} \;