我如何在其文件内容中找到包含一个特定的文本序列的所有文件?
下一个不起作用. 它似乎显示系统中的每个单一文件。
find / -type f -exec grep -H 'text-to-find-here' {} \;
我如何在其文件内容中找到包含一个特定的文本序列的所有文件?
下一个不起作用. 它似乎显示系统中的每个单一文件。
find / -type f -exec grep -H 'text-to-find-here' {} \;
当前回答
试试这:
find . | xargs grep 'word' -sl
其他回答
按要求轻松自定义下面的命令,并从文件中重复找到任何行。
grep -i hack $(find /etc/ -type f)
使用 grep -ilR:
grep -Ril "text-to-find-here" /
i 代表忽略案例(可选在您的案例中)。R 代表重复。l 代表“显示文件名,而不是结果本身”。 / 代表在您的机器的根源开始。
下面是可以用于搜索文件的几个命令列表。
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
我尝试了下面的捕捉命令,它有助于在 /etc/yum.repos.d 我的存储库中搜索内容。
grep -Ril -e 'texttoSearch' /etc/yum.repos.d
试试这:
find . | xargs grep 'word' -sl