相关问题:How do I find all files containing specific text on Linux?
我一直在使用上述问题的答案中提到的命令来搜索所有文件中的字符串出现情况:
grep -rnw '/path/to/somewhere/' -e "pattern"
但是最近我遇到了一个问题,如下图所示:
看起来此命令只能识别出单词或其他东西突出的字符串。我应该如何修改命令以改善搜索结果?
最佳答案
explainshell有助于说明您的命令,并摘录自man grep
:
-w, --word-regexp
Select only those lines containing matches that form whole words.
因此,只需删除
-w
即可,因为它明确地执行了您不想要的操作:grep -rn '/path/to/somewhere/' -e "pattern"