grep, but only certain file extensions

前端 未结 12 2517
野性不改
野性不改 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 04:00

    Just use the --include parameter, like this:

    grep -inr --include \*.h --include \*.cpp CP_Image ~/path[12345] | mailx -s GREP email@domain.com
    

    that should do what you want.

    To take the explanation from HoldOffHunger's answer below:

    • grep: command

    • -r: recursively

    • -i: ignore-case

    • -n: each output line is preceded by its relative line number in the file

    • --include \*.cpp: all *.cpp: C++ files (escape with \ just in case you have a directory with asterisks in the filenames)

    • ./: Start at current directory.

提交回复
热议问题