Searching for a specific text or pattern across multiple files can be completed using grep
.
Using grep
to search file contents
grep
provides searching functionality out-of-the-box:
|
|
Here are a breakdown of the grep
options:
-r
for recursiveness-n
for line number-w
for matching the whole word-e
is the pattern used for searching
The command will output the file names and text containing the pattern. If the goal is simply to display the filenames themselves, add the -l
flag.:
|
|
If binary files need to be omitted, add the -I
flag.
|
|
In addition, the --exclude
, --include
, and --exclude-dir
may be used in combination.
Example: Excluding dir1
and dir2
, find all html
or javascript
files with the filter of p
in them.
|
|