Bash 如何获取包含某行文本的所有文件(在一个目录中)的名称?

Bash 如何获取包含某行文本的所有文件(在一个目录中)的名称?,bash,Bash,例如: 我希望获得包含的所有文件的名称 start on startup 在/etc/init中,您可以尝试下面的grep命令 $ cd /etc/init $ grep -l "start on startup" * 或 通过一个命令, $ grep -l "start on startup" /etc/init/* 从man grep -l, --files-with-matches print only names of FILEs containing matches 您可以

例如:

我希望获得包含的所有文件的名称

start on startup 

/etc/init
中,您可以尝试下面的grep命令

$ cd /etc/init
$ grep -l "start on startup" *

通过一个命令,

$ grep -l "start on startup" /etc/init/*
man grep

-l, --files-with-matches  print only names of FILEs containing matches

您可以尝试下面的grep命令

$ cd /etc/init
$ grep -l "start on startup" *

通过一个命令,

$ grep -l "start on startup" /etc/init/*
man grep

-l, --files-with-matches  print only names of FILEs containing matches

我相信以下几点应该可以做到:

grep-ls“启动时启动”/etc/init/*

这将grep浏览
/etc/init
目录中的所有文件,并仅打印文件名,同时忽略任何错误(即
/etc/init/是一个目录

这里有一篇文章解释了
-l
选项:


下面是另一篇解释
-s
选项的帖子:

我认为下面应该可以做到这一点:

grep-ls“启动时启动”/etc/init/*

这将grep浏览
/etc/init
目录中的所有文件,并仅打印文件名,同时忽略任何错误(即
/etc/init/是一个目录

这里有一篇文章解释了
-l
选项:

下面是另一篇解释
-s
选项的文章: