Laxmikant Gurnalkar Laxmikant Gurnalkar - 2 months ago 17
Linux Question

grep recursively for a specific file type in Linux terminal

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

grep -Rin "onblur" *.html


This returns nothing. But,

grep -Rin "onblur" .


returns
"onblur"
search result from all available files, like in text(".txt"), .mako, .jinja etc.

Answer

Consider checking this answer and that one.

Also this might help you: grep certain file types recursively | commandlinefu.com.

The command is:

grep -r --include="*.[ch]" pattern .

And in your case it is:

grep -r --include="*.html" "onblur" .
Comments