Grep multiple current extension and subfolders

I am trying to grep several extensions in the current and all subfolders.

grep -i -r -n 'hello' somepath/*.{php,html}

This is only grepping the current folder, but not subfolders.

What would be a good way to do this?

+5
source share
3 answers

One of them:

find '(' -name '*.php' -o -name '*.html' ')' -exec grep -i -n hello {} +
find '(' -name '*.php' -o -name '*.html' ')' -print0 | xargs -0 grep -i -n hello
+2
source

Using grep only:

grep -irn --include='*.php' --include='*.html' 'hello' somepath/
+9
source

, bash script, vim , !

#!/bin/bash
context="$3"
#ln = line number mt =  match mc = file
export GREP_COLORS="sl=32:mc=00;33:ms=05;40;31:ln="
if [[ "$context" == "" ]]; then  context=5; fi
grep --color=always -n -a -R -i -C"$context" --exclude='*.mp*'\
 --exclude='*.avi'\
 --exclude='*.flv'\
 --exclude='*.png'\
 --exclude='*.gif'\
 --exclude='*.jpg'\
 --exclude='*.wav'\
 --exclude='*.rar'\
 --exclude='*.zip'\
 --exclude='*.gz'\
 --exclude='*.sql' "$2" "$1" | less -R

codesearch chmod 700 770 , ,

script

./codesearch '/full/path' 'string to search' 

5

./codesearch '/full/path' 'string to search' 3

example./codesearch./'eval' 2 screenshot codesearch

, " "

0
source

All Articles