加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

仅列出Linux中包含字符串的文件的名称

发布时间:2020-12-14 01:18:53 所属栏目:Linux 来源:网络整理
导读:我想列出使用 Linux命令包含字符串的文件的名称. 使用egrep时,会显示字符串的所有实例,这可能是倍数. 例如: egrep disco music_file*.txt 可能表现出来; music_file1.txt: blah blah blah disco stuffmusic_file1.txt: disco blah blah blahmusic_file1.txt
我想列出使用 Linux命令包含字符串的文件的名称.

使用egrep时,会显示字符串的所有实例,这可能是倍数.

例如:

egrep disco music_file*.txt

可能表现出来;

music_file1.txt: blah blah blah disco stuff

music_file1.txt: disco blah blah blah

music_file1.txt: I like to listen to italodisco

music_file2.txt: I like to party to disco

music_file3.txt: Does your dog like disco?

而我想要的只是:

music_file1.txt

music_file2.txt

music_file3.txt

问题:在Linux中搜索字符串时,如何只显示每个文件名的一个实例?

解决方法

将-l添加到egrep表达式:

egrep -l disco music_file*.txt

从男人grep:

-l,–files-with-matches

Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the first match. (-l is specified by POSIX.)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读