简体   繁体   English

Bash:管道找到Grep

[英]Bash : Piping Find into Grep

The following command finds all occurrences of 'some string' by recursively searching through the current directory and all sub-directories 以下命令通过递归搜索当前目录和所有子目录来查找所有出现的“some string”

grep -r -n  'some string' .

This command recursively searches through current directory and all sub-directories and returns all files of the form *.axvw 此命令以递归方式搜索当前目录和所有子目录,并返回* .axvw形式的所有文件

find . -name '*.axvw' 

I want to put these two commands together so I get all occurances of 'some string' by recursively searching through the current directory but only looking at files that end in 'axvw'. 我想把这两个命令放在一起,所以通过递归搜索当前目录,但只查看以'axvw'结尾的文件,我得到了所有'some string'。

When I tried running the following command nothing was returned: 当我尝试运行以下命令时,没有返回任何内容:

find . -name '*js' | grep -n  'some string'

What am I doing wrong? 我究竟做错了什么?

You can use -exec option in find : 您可以在find使用-exec选项:

find . -name '*.axvw' -exec grep -n 'some string' {} +

Or else use xargs : 或者使用xargs

find . -name '*.axvw' -print0 | xargs -0 grep -n 'some string'

find . -name '*js' -exec grep -n 'some string' {} \\;

Should work I think. 我认为应该工作。

Edit: just for fun, you could also use a double grep I believe. 编辑:只是为了好玩,你也可以使用双grep我相信。

find . | grep 'some string' | grep js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM