我如何将grep --include选项用于多种文件类型? [英] how do I use the grep --include option for multiple file types?
问题描述
当我想grep某个目录中的所有html文件时,我会执行以下操作:
grep --include =*。html pattern -R / some / path
效果很好。问题是如何在某些目录下grep所有的html,htm,php文件?
从这个使用grep --exclude / - 包含语法来不通过某些文件grep ,似乎我可以做以下
但遗憾的是,它不适合我。 grep --include =*。{html,php,htm}pattern -R / some / path $ c
FYI,我的grep版本是2.5.1。 --include
标志。这适用于我:
grep -r --include = *。html --include = *。php --include = *。htm pattern/ some / path /
然而,您可以像 Deruijter
建议。这适用于我:
grep -r --include = *。{html,php,htm}pattern/ some / path /
不要忘记您可以使用 find
和 xargs
用于这样的事情:
$ b
find / some / path / -name* .htm * - 或 - 名称* .php| xargs greppattern
HTH
When I want to grep all the html files in some directory, I do the following
grep --include="*.html" pattern -R /some/path
which works well. The problem is how to grep all the html,htm,php files in some directory?
From this Use grep --exclude/--include syntax to not grep through certain files, it seems that I can do the following
grep --include="*.{html,php,htm}" pattern -R /some/path
But sadly, it would not work for me.
FYI, my grep version is 2.5.1.
You can use multiple --include
flags. This works for me:
grep -r --include=*.html --include=*.php --include=*.htm "pattern" /some/path/
However, you can do as Deruijter
suggested. This works for me:
grep -r --include=*.{html,php,htm} "pattern" /some/path/
Don't forget that you can use find
and xargs
for this sort of thing to:
find /some/path/ -name "*.htm*" -or -name "*.php" | xargs grep "pattern"
HTH
这篇关于我如何将grep --include选项用于多种文件类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!