Grep Cookbook

Using grep by itself

search for “searchtext”, ignoring case, ignoring binary files, recurisvely search, with line numbers, in this folder.

grep -Iirn "searchtext" .

Just list filenames

search for “searchtext”, ignoring case, ignoring binary files, recurisvely search, just returning filenames, in this folder.

grep -iIrl "searchtext" .

more complex examples:

grep --exclude-dir="**.git**" --exclude-dir="**.ipynb_checkpoint**" --exclude="*.png" --exclude="*.svg" -iIrn "searchtext" .
grep -Iirl --exclude=*.svg --exclude-dir=**anaconda3** --exclude-dir=**Trash** tmux ~/

Using grep in a pipe

find all processes named python

ps aux | grep python

with a specific filetype

grep -Iirl "hello" --include=*.{cc,h} 

with newline

pcregrep -rIn -M "\n#{1} " --include=*.md .

GUI

sudo apt-get install libgtk-3-dev
pip install rummage