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

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

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

当前回答

试试:

find . -name "*.txt" | xargs grep -i "text_pattern"

其他回答

试试这:

find . | xargs grep 'word' -sl

重复和案例不敏感的捕捉与线号:

grep -inr "Text" folder/to/be/searched/

您可以使用 ripgrep 将遵守默认项目的.gitignore 文件。

此分類上一篇

拒绝许可的错误:

rg -i rustacean 2> /dev/null

将默认错误(stderr)输出转向 /dev/null。

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

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

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

apt-get install ack-grep

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

cd /
ack-grep "find my keyword"