我如何在其文件内容中找到包含一个特定的文本序列的所有文件?
下一个不起作用. 它似乎显示系统中的每个单一文件。
find / -type f -exec grep -H 'text-to-find-here' {} \;
我如何在其文件内容中找到包含一个特定的文本序列的所有文件?
下一个不起作用. 它似乎显示系统中的每个单一文件。
find / -type f -exec grep -H 'text-to-find-here' {} \;
当前回答
我很感动如何简单的吸引力使它与“rl”:
grep -rl 'pattern_to_find' /path/where/to/find
-r to recursively find a file / directory inside directories..
-l to list files matching the 'pattern'
使用“r”而不“l”以查看文件名跟随文本中的模式!
grep -r 'pattern_to_find' /path/where/to/find
它只是完美工作......
其他回答
Silver Searcher 是一个可怕的工具,但 ripgrep 可能甚至更好。
它在Linux、Mac和Windows上运行,并在几个月前在Hacker News上编写(它有一个链接到Andrew Gallant的博客,其中有一个GitHub链接):
Ripgrep - 新命令线搜索工具
有一个名为The Silversearcher的新工具
sudo apt install silversearcher-ag
它与 Git 和其他 VCS 密切合作,所以您不会在.git 或其他目录中获得任何东西。
你可以简单地使用
ag "Search query"
它会为你完成任务!
下面的命令将为此做得很好:
find ./ -name "file_pattern_name" -exec grep -r "pattern" {} \;
你的命令是正确的. 你只需要添加 -l 来抓住:
find / -type f -exec grep -l 'text-to-find-here' {} \;
如果您在 Git 存储库中,您可以使用:
git grep something