Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grep recursively for a specific file type on Linux

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.

like image 587
Laxmikant Ratnaparkhi Avatar asked Mar 06 '14 12:03

Laxmikant Ratnaparkhi


People also ask

How do I grep to a specific file type?

Specifying File Type To do so, we can use a special type of option that starts with two hyphens: $ grep -ri "hello" --include=*. cc Test/test.cc:Hello World!

How do I grep a specific file in Linux?

The grep command searches through the file, looking for matches to the pattern specified. To use it type grep , then the pattern we're searching for and finally the name of the file (or files) we're searching in. The output is the three lines in the file that contain the letters 'not'.

How do I recursively grep a file?

To recursively search for a pattern, invoke grep with the -r option (or --recursive ). When this option is used grep will search through all files in the specified directory, skipping the symlinks that are encountered recursively.


1 Answers

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" . 
like image 73
dnl-blkv Avatar answered Sep 20 '22 08:09

dnl-blkv