Home > shell tips > bash: Find specifying certain file extensions

bash: Find specifying certain file extensions

November 2nd, 2011 Leave a comment Go to comments
I had terrible trouble finding a way to do this in bash, doesn’t seem to be possible using -name or -iname :-

find /var/www/html/ -regex “.*\(php\|js\|inc\)” -exec grep -i ‘tbl_title’ {} +

find /var/www/html/ -regex “.*\(php\|js\|inc\)” -exec grep -i ‘tbl_title’ {} \;

NB: the \; and + endings are different the + ending usefully displays the matching file name

Of course if you have a recent bash you will likely prefer:-

grep -ilR –include=*.{php,inc,js} ‘fn_main’ c:/inetpub/wwwroot

or

grep -iR –include=*.{php,inc,js} ‘fn_main’ c:/inetpub/wwwroot

Categories: shell tips Tags:
  1. No comments yet.
  1. No trackbacks yet.