我如何在其文件内容中找到包含一个特定的文本序列的所有文件?
下一个不起作用. 它似乎显示系统中的每个单一文件。
find / -type f -exec grep -H 'text-to-find-here' {} \;
我如何在其文件内容中找到包含一个特定的文本序列的所有文件?
下一个不起作用. 它似乎显示系统中的每个单一文件。
find / -type f -exec grep -H 'text-to-find-here' {} \;
当前回答
避免混乱并安装 ack-grep. 它消除了许多许可和引用问题。
apt-get install ack-grep
然后转到您想要搜索的目录,并运行下面的命令。
cd /
ack-grep "find my keyword"
其他回答
您可以使用 ripgrep 将遵守默认项目的.gitignore 文件。
此分類上一篇
拒绝许可的错误:
rg -i rustacean 2> /dev/null
将默认错误(stderr)输出转向 /dev/null。
重复和案例不敏感的捕捉与线号:
grep -inr "Text" folder/to/be/searched/
find /path -type f -exec grep -l "string" {} \;
评论的解释
查找是一个命令,允许您在特定路径的子目录中找到文件和其他对象,如目录和链接,如果您不指定该文件名称应满足的面具,则列出所有目录对象。
-type f specifies that it should proceed only files, not directories etc.
-exec grep specifies that for every found file, it should run grep command, passing its filename as an argument to it, by replacing {} with the filename
试试:
find / -type f -exec grep -H 'text-to-find-here' {} \;
将搜索所有文件系统,因为 / 是根文件夹。
Home 文件夹使用:
find ~/ -type f -exec grep -H 'text-to-find-here' {} \;
目前使用文件夹:
find ./ -type f -exec grep -H 'text-to-find-here' {} \;
如果你有一组文件,你会一直在检查,你可以列出他们的路径,例如:
alias fd='find . -type f -regex ".*\.\(inc\|info\|module\|php\|test\|install\|uninstall\)"'
然后你可以简单地过滤列表如下:
grep -U -l $'\015' $(fd)
将列表 fd 过滤到包含 CR 模式的文件。
我发现,将我感兴趣的文件会帮助我创建更容易的脚本,然后总是试图记住如何获得所有这些文件。 回复的物品工作,但早或晚你将不得不争取分散特定的文件类型。