Here is a quick example:
$ grep -r "text string to search” directory-path
To search for a string ‘logged in’ in all text (*.log) files located in /etc/networks/ directory for example, use:
$ grep "logged in" /etc/networks/*.log
To search all subdirectories recursively, include -r option like so:
$ grep -r "logged in" /etc/networks/*.log
The grep command prints the matching lines for each match. Pass -H option to print the filename only:
$ grep -H -r "logged in" /etc/networks/*.log
To search for two or more words, use egrep:
egrep -w -r 'logged in|logged out' /etc/networks/*.log
To hide warning spam of permission for certain directories being denied, etc, send them to dev/null:
$ grep -w -r 'logged in|logged out' /etc/networks/*.log 2>/dev/null
To make it case insensitive, use -i option:
$ grep -i "logged in" /etc/networks/*.log