我正在从根目录递归地寻找一个特定的字符串(主要在 .c 文件中)。
当我使用它时,我几乎立即得到一个列表。
grep -rl "F_capture" .
但是,如果我试图通过搜索 .c 文件来加快速度:
grep -r --include=*.c "F_capture" .
我最终得到了一系列这样的递归目录警告:
grep: warning: ./sys/block/fd0/device/bus/drivers/i8042/i8042/serio1/input:event1/subsystem/event3/device/bus/drivers/pcnet32/0000:00:03.0/subsystem: recursive directory loop
当我尝试使用 -s 参数抑制警告时,我没有收到警告,但我也没有得到任何回复 - 似乎它永远不会降落。
grep -rsl --include="*.c" "F_capture" .
所以我想我的问题是,为什么我使用的第一个 grep 立即返回一些东西,而我针对特定类型文件的其他类型似乎挂断了。我认为有针对性的搜索会更快。
最佳答案
你可以试试这个:
find . -type f -name "*.c" -print|xargs grep -l "F_capture"
关于linux - grep 递归 - 不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24685387/