我想在包含递归目录
和文件
的目录
中搜索多个模式
。
我知道 grep
命令如下
grep -e '(pattern1)|(pattern2)'
或
grep -r -E 'string1|string2|string3' /var/www/http
使用 ack
或 ag
的命令是什么?
最佳答案
这应该足够了:
ack -R 'string1|string2'
因为 -R
是默认的,你可以省略它:
ack 'string1|string2'
来自 man ack
:
-r, -R, --recurse
Recurse into sub-directories. This is the default and just here for compatibility with grep. You can also use it for turning --no-recurse off.
如果你想从文件中获取模式,比如/path/to/patterns.file,你可以使用:
ack "$(cat /path/to/patterns.file)"
或等价地:
ack "$(< /path/to/patterns.file)"
我找不到与 grep -f
完全相同的词。
关于linux - 使用 ack 搜索多个模式(单词)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26275582/