Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

grep - 如何使用grep在文件夹中查找单词?(How can I use grep to find a word inside a folder?)

In Windows, I would have done a search for finding a word inside a folder.

(在Windows中,我会搜索在文件夹中查找单词。)

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, ie grep string filename .

(我对grep语法的搜索显示我必须指定文件名,即grep string filename 。)

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 ctrl + c ).

(一位朋友建议做grep -nr string ,但我不知道这意味着什么,我没有得到任何结果(在我发出ctrl + c之前没有响应)。)

  ask by kiki translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
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*' . (Would find MobileAppServlet.java or MobileAppServlet.class or MobileAppServlet.txt ; 'MobileAppASer*.*' is another way to do the same thing.)

((会找到MobileAppServlet.javaMobileAppServlet.classMobileAppServlet.txt ; 'MobileAppASer*.*'是另一种做同样事情的方法。))

To check more parameters use man grep command.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...