找出一个单词包含在哪个文件中的最简单方法是什么?

Edw*_*uay 0 linux unix bash command-line-interface

我在下面的“ lxadmin ”目录中有许多 .conf 文件,并怀疑文本“ tanguay.info ”在其中之一的某个地方。

我执行这个命令:

cat /etc/httpd/conf/lxadmin/* | grep "tanguay.info"
Run Code Online (Sandbox Code Playgroud)

它告诉我:

cat: /etc/httpd/conf/lxadmin/forward: Is a directory
Include /home/httpd/tanguay.info/conf/lxadmin.tanguay.info
Run Code Online (Sandbox Code Playgroud)

所以我知道它在某处,但它没有告诉我在哪个文件中

我怎样才能让它也告诉我文本位于哪个文件中?

Bab*_*abu 14

grep "tanguay.info" /etc/httpd/conf/lxadmin/*,只要文件不在子目录中即可。


chm*_*eee 14

如果有子目录,您可以使用

rgrep "tanguay.info" /etc/httpd/conf/lxadmin/
Run Code Online (Sandbox Code Playgroud)

或者

grep -r "tanguay.info" /etc/httpd/conf/lxadmin/
Run Code Online (Sandbox Code Playgroud)

编辑:

您还可以使用ack,一种用 perl 编写的增强型 grep(独立版本不需要 deps)。ack 默认通过目录递归搜索。

ack "tanguay.info" /etc/httpd/conf/lxadmin/
Run Code Online (Sandbox Code Playgroud)

在 Ubuntu 上,您可以在 ack-grep 包中找到它。