我如何使用grep在文件夹中查找单词? [英] How can I use grep to find a word inside a folder?

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

问题描述

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



现在,我不知道文件名,那我该怎么办?
朋友建议做 grep -nr string ,但我不知道这意味着什么,我没有得到任何结果(直到我没有回应发布一个 ctrl + c )。

解决方案

  grep  - nr'yourString *'。 

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

  -n在文件中显示相对行号
'yourString *'用于搜索的字符串,后跟一个通配符
-r递归搜索列出的
子目录。搜索目录(当前目录)

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



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


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.

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 '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.)

To check more parameters use man grep command.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆