2017-03-17 56 views
0

我有这样的搜索 - 我想打印出包含匹配文本文件的路径:搜索包含模式的文件

grep -r "jasmine" . 

和它产生的结果是这样的:

./app-root/runtime/repo/node_modules/jasmine-core/.github/CONTRIBUTING.md:- [Jasmine Google Group](http://groups.google.com/group/jasmine-js) 
./app-root/runtime/repo/node_modules/jasmine-core/.github/CONTRIBUTING.md:- [Jasmine-dev Google Group](http://groups.google.com/group/jasmine-js-dev) 
./app-root/runtime/repo/node_modules/jasmine-core/.github/CONTRIBUTING.md:git clone [email protected]:yourUserName/jasmine.git    # Clone your fork 
./app-root/runtime/repo/node_modules/jasmine-core/.github/CONTRIBUTING.md:cd jasmine              # Change directory 
./app-root/runtime/repo/node_modules/jasmine-core/.github/CONTRIBUTING.md:git remote add upstream https://github.com/jasmine/jasmine.git # Assign original repository to a remote named 'upstream' 
./app-root/runtime/repo/node_modules/jasmine-core/.github/CONTRIBUTING.md:Note that Jasmine tests itself. The files in `lib` are loaded first, defining the reference `jasmine`. Then the files in `src` are loaded, defining the reference `j$`. So there are two copies of the code loaded under test. 
./app-root/runtime/repo/node_modules/jasmine-core/.github/CONTRIBUTING.md:The tests should always use `j$` to refer to the objects and functions that are being tested. But the tests can use functions on `jasmine` as needed. _Be careful how you structure any new test code_. Copy the patterns you see in the existing code - this ensures that the code you're testing is not leaking into the `jasmine` reference and vice-versa. 

但是我只是想要文件名,我不想打印出匹配的内容,只是文件名,我该怎么办?

问题是,匹配文本将环绕在终端中,并使结果基本上不可读。

回答

1

您是否使用grep-l标志?

-l,--files与 - 匹配

禁止正常输出;而是打印每个输出文件的名称,通常从哪个输出文件打印出来。扫描将在第一场比赛中停止。

在我的主目录一个简单的搜索,

grep -rl 'bash' . 
./.bashrc 
./.bash_history 
./.bash_logout 
./.bash_profile 
./.profile 
./.viminfo 

由于事实上,-lgrep一个POSIX defined option应在几乎所有发行版可用。

+0

尚未测试它,今天会给它一个去吧 –

+0

接受,似乎工作,谢谢 –