Answers:
我建议使用以下--include选项grep:
grep -lr --include='*.c' search-pattern .
.对命令末尾的目的感到困惑。
该*.c模式由您的外壳评估。就像您使用一样,它适用于当前目录ls *.c。
我认为您要查找的是与该*.c模式匹配的所有文件(递归),并在其中grep搜索您。这是一种方法:
find . -name "*.c" -print0 | xargs --null grep -l search-pattern
它用于xargs将搜索结果附加到find。
或者,使用该-exec选项查找,例如:
find . -name "*.c" -exec grep -l search-pattern "{}" \;
另外,我不确定您是否真的想要该-l选项grep。它将在第一场比赛停止:
-l, --files-with-matches
Suppress normal output; instead print the name of each
input file from which output would normally have been
printed. The scanning will stop on the first match.
(-l is specified by POSIX.)
find/xargs含有空格的文件名语法休息。该-L的选项grep停止对每个文件的第一场比赛,并继续下一个文件:如果一个人只是想看看是否图案中的每个给定的文件包含至少一次,它的速度更快。
-print0option和修复了它xargs --null。
--include=GLOB选项。结合使用递归选项,此功能非常强大,不需要find。真好!