小编典典

如何使用 grep 在文件夹中查找单词?

all

在 Windows 中,我会搜索文件夹中的单词。同样,我想知道特定单词是否出现在包含许多子目录和文件的目录中。我对 grep
语法的搜索显示我必须指定文件名,即grep string filename.

现在,我不知道文件名,那我该怎么办?一位朋友建议这样做grep -nr string,但我不知道这是什么意思,我没有得到任何结果(在我发出Ctrl+之前没有回应C)。


阅读 148

收藏
2022-03-04

共1个答案

小编典典

grep -nr 'yourString*' .

末尾的点搜索当前目录。每个参数的含义:

-n            Show relative line number in the file
'yourString*' String for search, followed by a wildcard character
-r            Recursively search subdirectories listed
.             Directory for search (current directory)

grep -nr 'MobileAppSer*' .
(会发现MobileAppServlet.javaorMobileAppServlet.classMobileAppServlet.txt;'MobileAppASer*.*'是做同样事情的另一种方式。)

要检查更多参数,请使用 man grep 命令。

2022-03-04