RockPaperScissors

LizardSpock

Recursive Grep, with Filtering

| Comments

I noticed today that greps recursive function is different to finds recursion.

find ./ -name *.txt
grep -R 'text' *.text

The above find command will search from the sub-directory down while grep will only search the current folder. The FILE_PATTERN must also match the hierarchy in grep.

To apply a file type filter in grep you can do:

grep -R --include=*.txt 'text' ./

This looks at all file from the current directory (./) but will only grep files which match the include.

An older article on Basic grep usage.

Comments