我如何在其文件内容中找到包含一个特定的文本序列的所有文件?
下一个不起作用. 它似乎显示系统中的每个单一文件。
find / -type f -exec grep -H 'text-to-find-here' {} \;
我如何在其文件内容中找到包含一个特定的文本序列的所有文件?
下一个不起作用. 它似乎显示系统中的每个单一文件。
find / -type f -exec grep -H 'text-to-find-here' {} \;
当前回答
按要求轻松自定义下面的命令,并从文件中重复找到任何行。
grep -i hack $(find /etc/ -type f)
其他回答
重复和案例不敏感的捕捉与线号:
grep -inr "Text" folder/to/be/searched/
您可以使用捕捉工具重复搜索当前文件夹,如:
grep -r "class foo" .
注意: -r - 重复搜索分支机构。
grep "class foo" **/*.c
如果你有错误,你的论点太长,考虑缩短你的搜索,或者使用找到合成代替,如:
find . -name "*.php" -execdir grep -nH --color=auto foo {} ';'
或者使用Ripgrep。
rg "class foo" .
它比任何其他工具,如 GNU/BSD grep, ucg, ag, sift, ack, pt 或类似,因为它是建立在Rust的 regex 引擎的顶部,使用终端自动化,SIMD和攻击性字体优化,使搜索非常快。
-i - 不敏感的搜索. -I - 忽略二进制文件. -w - 搜索完整的单词(相反的部分单词匹配)。 -n - 显示您的匹配线. -C/--背景(例如 -C5) - 增加背景,所以你看到周围的代码. --color=auto - 标记匹配文本. -H - 显示文件名,在文本中找到。
要搜索字符串和输出,就是与搜索字符串相同的字符串:
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;
GUI Search Alternative - 用于桌面使用:
因为问题不准确要求命令。
Searchmonkey: Advanced file search tool without having to index your system using regular expressions. 图形相当于查找/查找. 可用于 Linux (Gnome/KDE/Java) 和 Windows (Java) - 开源 GPL v3
特性:
Advanced Regular Expressions Results shown in-context Search containing text Panel to display line containing text 新 2018 更新等。
下载 - 链接:
主页: http://searchmonkey.embeddediq.com/ 下载: http://searchmonkey.embeddediq.com/index.php/download-latest Repo: https://sourceforge.net/projects/searchmonkey/files/
是
屏幕射击:
此分類上一篇
格雷普是你的好朋友来实现这一点。
grep -r <text_fo_find> <directory>
如果你不在乎要找到文本的案例,那么使用:
grep -ir <text_to_find> <directory>