我如何使用grep在Linux上显示文件名(没有内嵌匹配)? [英] How can I use grep to show just filenames (no in-line matches) on Linux?

查看:116
本文介绍了我如何使用grep在Linux上显示文件名(没有内嵌匹配)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Linux上使用 grep 来显示文件名(无内嵌匹配)?



<我通常使用类似于:

  find。 -iname* php-exec grep -H myString {} \; 

如何获取文件名(带路径),但没有匹配?我是否必须使用 xargs ?我没有看到在我的 grep 手册页上执行此操作的方法。

解决方案

标准选项 grep -l <​​/ code>(即小写的L)可以做到这一点。



From Unix标准

  -l 
(英文字母)仅将包含选定
行的文件的名称写入标准输出。每个搜索的文件都会写入一次路径名。
如果搜索到标准输入,则将在POSIX语言环境中写入(标准输入)的路径名
。在其他语言环境中,标准输入可能会被这些语言环境中更适合的内容替换为

您也不需要 -H 在这种情况。


How can I use grep to show just file-names (no in-line matches) on Linux?

I am usually using something like:

find . -iname "*php" -exec grep -H myString {} \;

How can I just get the file-names (with paths), but without the matches? Do I have to use xargs? I didn't see a way to do this on my grep man page.

解决方案

The standard option grep -l (that is a lowercase L) could do this.

From the Unix standard:

-l
    (The letter ell.) Write only the names of files containing selected
    lines to standard output. Pathnames are written once per file searched.
    If the standard input is searched, a pathname of (standard input) will
    be written, in the POSIX locale. In other locales, standard input may be
    replaced by something more appropriate in those locales.

You also do not need -H in this case.

这篇关于我如何使用grep在Linux上显示文件名(没有内嵌匹配)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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