shell - 如何对多种文件类型使用 grep --include 选项?

标签 shell grep

当我想 grep 某个目录中的所有 html 文件时,我执行以下操作

grep --include="*.html"模式 -R/some/path

效果很好。问题是如何grep某个目录中的所有html、htm、php文件?

从此Use grep --exclude/--include syntax to not grep through certain files ,看来我可以做以下事情

grep --include="*.{html,php,htm}"模式 -R/some/path

但遗憾的是,它对我不起作用。
仅供引用,我的 grep 版本是 2.5.1。

最佳答案

您可以使用多个 --include 标志。这对我有用:

grep -r --include=*.html --include=*.php --include=*.htm "pattern" /some/path/

但是,您可以这样做 Deruijter suggested 。这对我有用:

grep -r --include=*.{html,php,htm} "pattern" /some/path/

不要忘记,您也可以使用 findxargs 来完成此类事情:

find /some/path/ -name "*.htm*" -or -name "*.php" | xargs grep "pattern"

关于shell - 如何对多种文件类型使用 grep --include 选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10619160/

相关文章:

linux - grep awk 忽略字符

linux - 将 Linux 服务器的文本文件中的行与条件结合起来

linux - 使用 sed 从日志文件中提取目录

linux - 如何在不修改字符串内容的情况下回显包含引号的字符串?

javascript - 未找到 `.mongorc.js`,但有一个

linux - 使用 shell 脚本进行 CSV 操作

bash - 如何使用 bash 在 CURL 请求中使用变量?

linux - Bash:从 ls -l 读取专栏

regex - 如何以尽可能少的开销将 c 中的所有函数内容与正则表达式匹配

bash - 替换不在括号中的数字?