使用带目录参数的 grep 时如何限制文件扩展名?

How to restrict file extension when using grep with a directory parameter?

grep -nr 'queryTag' .

比如我当前目录下有多个目录,我想搜索关键字'queryTag'。但是,我想将搜索限制为文件类型“.txt”,而不是当前目录中的所有文件。如何修改上面的命令?

您可以使用 --include= 选项:

grep -nr 'queryTag' --include='*.txt' .