我如何在其文件内容中找到包含一个特定的文本序列的所有文件?
下一个不起作用. 它似乎显示系统中的每个单一文件。
find / -type f -exec grep -H 'text-to-find-here' {} \;
我如何在其文件内容中找到包含一个特定的文本序列的所有文件?
下一个不起作用. 它似乎显示系统中的每个单一文件。
find / -type f -exec grep -H 'text-to-find-here' {} \;
当前回答
使用:
grep -Erni + "text you wanna search"
命令将重复搜索当前目录的所有文件和目录,并打印结果。
注意:如果您的格雷普输出没有颜色,您可以通过在您的壳源文件中使用格雷普=‘格雷普=颜色=总是’的标志来更改它。
其他回答
重复和案例不敏感的捕捉与线号:
grep -inr "Text" folder/to/be/searched/
要搜索字符串和输出,就是与搜索字符串相同的字符串:
for i in $(find /path/of/target/directory -type f); do grep -i "the string to look for" "$i"; done
吉:
for i in $(find /usr/share/applications -type f); \
do grep -i "web browser" "$i"; done
要显示包含搜索字符串的文件名:
for i in $(find /path/of/target/directory -type f); do if grep -i "the string to look for" "$i" > /dev/null; then echo "$i"; fi; done;
吉:
for i in $(find /usr/share/applications -type f); \
do if grep -i "web browser" "$i" > /dev/null; then echo "$i"; \
fi; done;
正如彼得在以前的回答中提到的那样,所有以前的回答都建议抓住并找到。
但有一个更复杂的方式使用Gnome Commander与完美的GUI和数以百万计的选项自2001年以来,并找到文件只是其中之一。
我认为值得提到你如何找到:
所有包含至少一个文本的文件,其中包括大量的文本:
grep -rlf ../patternsFile.txt .
出口:
./file1
./file2
./file4
上述,由每个文本组成:
cat ../patternsFile.txt | xargs -I{} sh -c "echo {}; grep -rl \"{}\" ."
出口:
pattern1
./file1
./file2
pattern2
./file1
./file4
pattern3
./file1
./file2
./file4
请注意,为了不匹配模式File.txt本身,您需要添加一个目录(如上面的示例所示)。
试试:
find . -name "*.txt" | xargs grep -i "text_pattern"