我如何在其文件内容中找到包含一个特定的文本序列的所有文件?
下一个不起作用. 它似乎显示系统中的每个单一文件。
find / -type f -exec grep -H 'text-to-find-here' {} \;
我如何在其文件内容中找到包含一个特定的文本序列的所有文件?
下一个不起作用. 它似乎显示系统中的每个单一文件。
find / -type f -exec grep -H 'text-to-find-here' {} \;
当前回答
有一个Ack工具,它会做你正在寻找的东西:
ack -i search_string folder_path/*
您可能会忽略 -i 对案例敏感搜索。
其他回答
您可以使用以下命令从文件中找到特定文本:
cat file | grep 'abc' | cut -d':' -f2
这个捕捉命令会给你一个准确的结果,当你正在寻找特定的文本在Linux -
grep -inRsH “文本要被搜索” /path/to/dir(它可以是“。
i stands for ignore case distinctions R stands for recursive and it also includes symlinks. It is better to use 'R' instead of 'r' n stands for "it will print line number." s stands for "suppress error messages" H stands for "it will print the file name for each match"
使用 pwd 从您所在的任何目录中搜索,向下滑动
grep -rnw `pwd` -e "pattern"
取决于您正在使用的 grep 版本,您可以忽略 pwd. 在更新的版本中,如果没有目录,则似乎是 grep 的默认情况。
这样:
格雷普 -rnw -e “模式”
或
格雷普 -rnw “模式”
他们会像上面那样做!
所有以前的答案都建议抓住和找到,但还有另一种方式:使用中夜指挥官
它是一个免费的工具(30年,时间证明),它是视觉的没有GUI. 它有许多功能,找到文件只是其中之一。
包含特定文本的文件名列表
首先,我相信你使用了 -H 而不是 -l. 你也可以尝试在引用中添加文本,其次是 {} \。
find / -type f -exec grep -l "text-to-find-here" {} \;
例子
假设您正在寻找包含特定文本“Apache 许可证”的文件在您的目录中,它将显示一些类似于下面的结果(结果将根据您的目录内容不同)。
bash-4.1$ find . -type f -exec grep -l "Apache License" {} \;
./net/java/jvnet-parent/5/jvnet-parent-5.pom
./commons-cli/commons-cli/1.3.1/commons-cli-1.3.1.pom
./io/swagger/swagger-project/1.5.10/swagger-project-1.5.10.pom
./io/netty/netty-transport/4.1.7.Final/netty-transport-4.1.7.Final.pom
./commons-codec/commons-codec/1.9/commons-codec-1.9.pom
./commons-io/commons-io/2.4/commons-io-2.4.pom
bash-4.1$
取消案例敏感性
即使你不使用案例如“文本”与“文本”,你可以使用 -i 交换来忽略案例。