how do I use the grep --include option for multiple file types?

后端 未结 7 1897
故里飘歌
故里飘歌 2020-12-04 10:40

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. T

7条回答
  •  离开以前
    2020-12-04 11:10

    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

提交回复
热议问题