我如何在其文件内容中找到包含一个特定的文本序列的所有文件?
下一个不起作用. 它似乎显示系统中的每个单一文件。
find / -type f -exec grep -H 'text-to-find-here' {} \;
我如何在其文件内容中找到包含一个特定的文本序列的所有文件?
下一个不起作用. 它似乎显示系统中的每个单一文件。
find / -type f -exec grep -H 'text-to-find-here' {} \;
当前回答
你的命令是正确的. 你只需要添加 -l 来抓住:
find / -type f -exec grep -l 'text-to-find-here' {} \;
其他回答
如果你有一组文件,你会一直在检查,你可以列出他们的路径,例如:
alias fd='find . -type f -regex ".*\.\(inc\|info\|module\|php\|test\|install\|uninstall\)"'
然后你可以简单地过滤列表如下:
grep -U -l $'\015' $(fd)
将列表 fd 过滤到包含 CR 模式的文件。
我发现,将我感兴趣的文件会帮助我创建更容易的脚本,然后总是试图记住如何获得所有这些文件。 回复的物品工作,但早或晚你将不得不争取分散特定的文件类型。
试试:
find . -name "*.txt" | xargs grep -i "text_pattern"
下面是可以用于搜索文件的几个命令列表。
grep "text string to search” directory-path
grep [option] "text string to search” directory-path
grep -r "text string to search” directory-path
grep -r -H "text string to search” directory-path
egrep -R "word-1|word-2” directory-path
egrep -w -R "word-1|word-2” directory-path
格雷普是你的好朋友来实现这一点。
grep -r <text_fo_find> <directory>
如果你不在乎要找到文本的案例,那么使用:
grep -ir <text_to_find> <directory>
试试这:
find . | xargs grep 'word' -sl