首页 > 解决方案 > 为什么 grep 无法在文件中找到模式

问题描述

我在尝试

grep -rn '*.cpp' -e 'aPattern'

aPattern在包含 cpp 文件的目录中递归查找模式,但我得到了

*.cpp no such file or directory

为什么会失败?子目录中有cpp文件

标签: grep

解决方案


找到了解决办法

grep -rn --include '*.hpp' -e 'aPattern'

关键是放--include

更好

grep --color -rn --include '*.hpp' -e 'aPattern'

推荐阅读