我如何在其文件内容中找到包含一个特定的文本序列的所有文件?
下一个不起作用. 它似乎显示系统中的每个单一文件。
find / -type f -exec grep -H 'text-to-find-here' {} \;
我如何在其文件内容中找到包含一个特定的文本序列的所有文件?
下一个不起作用. 它似乎显示系统中的每个单一文件。
find / -type f -exec grep -H 'text-to-find-here' {} \;
当前回答
试试这
find . -type f -name some_file_name.xml -exec grep -H PUT_YOUR_STRING_HERE {} \;
其他回答
要搜索字符串和输出,就是与搜索字符串相同的字符串:
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;
重复和案例不敏感的捕捉与线号:
grep -inr "Text" folder/to/be/searched/
A Simple find can work handy. alias it in your ~/.bashrc 文件:
alias ffind find / -type f | xargs grep
开始一个新的终端和问题:
ffind 'text-to-find-here'
试试这
find . -type f -name some_file_name.xml -exec grep -H PUT_YOUR_STRING_HERE {} \;
您可以使用下面的命令,因为您不想要文件名,但您想要从所有文件中搜索。
grep -e TEXT *.log | cut -d' ' --complement -s -f1
捕捉与 -e 选项是相当快的与其他选项相比,因为它是PATTERN 比赛