grep
Recursive case insensitive search; print the filename and the line:
_$: grep -nri "word" ./file
Recursive case insensitive search; print just the filename:
_$: grep -lri "word" ./file
Search when multiple matches per line are possible:
_$: grep -o "word" ./file
Search with basic regular expressions (BRE):
_$: grep -n "^wor*" ./file
Search with extended regular expressions (ERE):
_$: grep -nE "(word1|word2)" ./file
Search with Perl-compatible regular expressions (PCRE):
_$: grep -oE "GET /ru/.* HTTP/1.1\" 404" access.log.1 | grep -oP "/ru/.*? "
Ignoring a directory:
_$: grep -nri --exclude-dir='dir' "word" ./*
find + grep
Find all files older than a year with the word ** SPAM **
:
_$: grep -l '** SPAM **' $(find . -mtime +365)
Find all files older than a year with the word ** SPAM **
and delete them:
_$: find . -mtime +365 -print0 | xargs -0 -I {} grep -l '** SPAM **' {} | xargs -I {} rm {}