Linux:在所有文件中搜索特定单词

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14445005/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 18:45:07  来源:igfitidea点击:

Linux : Search for a particular word in all the files

linuxgrep

提问by Pawan

I am using Ubuntu 12 . I am trying to search for the word "SymbolSetThree" in my Ubuntu Machine home directory .

我正在使用 Ubuntu 12 。我试图在我的 Ubuntu 机器主目录中搜索“SymbolSetThree”这个词。

For this i used

为此,我使用了

 grep "SymbolSetThree" /home

It simply displayed as grep: /home: Is a directory

它简单地显示为 grep: /home: Is a directory

Please let me know how to search for a particular word in all the files in Linux ??

请让我知道如何在 Linux 的所有文件中搜索特定单词?

This is what i tried

这是我试过的

sai@sai-Aspire-4720Z:/$  grep "SymbolSetThree" /home
grep: /home: Is a directory

回答by NPE

Use `find:

使用`查找:

find /home -type f | xargs grep SymbolSetThree

The same result can be achieved by using the -execargument to find(instead of xargs).

通过使用-exec参数 to find(而不是xargs)可以获得相同的结果。

回答by Gilles Quenot

You are close, you just need the -rswitch to have your command working properly.

你很接近,你只需要-r开关让你的命令正常工作。

 grep -r "SymbolSetThree" /home

will do the trick.

会做的伎俩。

回答by MGP

For this kind of tasks I really like ack-grep, is programmer oriented (only source files, .py .rb .c .sh) but with -a it looks for all kind of files.

对于这类任务,我非常喜欢 ack-grep,它是面向程序员的(只有源文件,.py .rb .c .sh),但使用 -a 可以查找所有类型的文件。

ack-grep -a "SymbolSetThree"