grep, but only certain file extensions

前端 未结 12 2525
野性不改
野性不改 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:59

    Should write "-exec grep " for each "-o -name "

    find . -name '*.h' -exec grep -Hn "CP_Image" {} \; -o -name '*.cpp' -exec grep -Hn "CP_Image" {} \;
    

    Or group them by ( )

    find . \( -name '*.h' -o -name '*.cpp' \) -exec grep -Hn "CP_Image" {} \;
    

    option '-Hn' show the file name and line.

提交回复
热议问题