grep recursively for a specific file type on Linux

前端 未结 4 1377
抹茶落季
抹茶落季 2020-12-23 10:08

Can we search a term (eg. \"onblur\") recursively in some folders only in specific files (html files)?

grep -Rin \"onblur\" *.html

This ret

4条回答
  •  感动是毒
    2020-12-23 10:27

    Have a look at this answer instead, to a similar question: grep, but only certain file extensions

    This worked for me. In your case just type the following:

    grep -inr "onblur" --include \*.html ./
    

    consider that

    • grep: command

    • -r: recursively

    • -i: ignore-case

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

    • --include \*.html: escape with \ just in case you have a directory with asterisks in the filenames

    • ./: start at current directory.

提交回复
热议问题