Examples using Grep to search multiple files or directories.
Grep multiple files
Simply provide a list of files to search
grep "admin" jslog.txt apachelog.txt
Grep files in a directory
-r (recursive) flag and a directory to Grep within every file found within that directory. In the below example we’re searching the ‘logs’ directory:
grep -r "Success:400" logs
Grep within the current directory
. instead of a directory name to indicate that Grep should search within files in the current directory.
grep -r "error" .
Grep files with a specific file extension
Search within files that have a certain file extension by utilizing Grep’s
--include flag. The following example will only Grep
.js files within the ‘site’ directory:
grep -r "admin" site --include \*.js