grep, but only certain file extensions

前端 未结 12 2527
野性不改
野性不改 2020-12-02 03:18

I am working on writing some scripts to grep certain directories, but these directories contain all sorts of file types.

I want to grep jus

12条回答
  •  天涯浪人
    2020-12-02 03:52

    I am aware this question is a bit dated, but I would like to share the method I normally use to find .c and .h files:

    tree -if | grep \\.[ch]\\b | xargs -n 1 grep -H "#include"
    

    or if you need the line number as well:

    tree -if | grep \\.[ch]\\b | xargs -n 1 grep -nH "#include"
    

提交回复
热议问题