在文件夹中查找单词

在文件夹中查找单词

本文介绍了如何使用 grep 在文件夹中查找单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In Windows, I would have done a search for finding a word inside a folder. Similarly, I want to know if a specific word occurs inside a directory containing many sub-directories and files. My searches for grep syntax shows I must specify the filename, i.e. grep string filename.

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

Now, I do not know the filename, so what do I do?A friend suggested to do grep -nr string, but I don't know what this means and I got no results with it (there is no response until I issue a + ).

推荐答案

grep -nr 'yourString*' .

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

The dot at the end searches the current directory. Meaning for each parameter:

-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.javaMobileAppServlet.classMobileAppServlet.txt; 'MobileAppASer*.*' 是另一种做同样事情的方式.)

grep -nr 'MobileAppSer*' . (Would find MobileAppServlet.java or MobileAppServlet.class or MobileAppServlet.txt; 'MobileAppASer*.*' is another way to do the same thing.)

要查看更多参数,请使用 ma​​n grep 命令.

To check more parameters use man grep command.

这篇关于如何使用 grep 在文件夹中查找单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 18:42