Linux grep Command
About
grep
is a string and pattern matching utility that displays matching lines found in files using common regular expressions. It can also work with piped output from other commands.
The utility was named after the ed
command string g/re/p
, which translates as “global regular expression search.”
Syntax:
grep <search pattern> <location>
Examples
Find a string within a file
Find all instances of the string my string
in the threads.txt
file in the users home directory:
grep "my string" ~/threads.txt
Find a string within files in a directory
Find all instances of the string my string
in the files under the /path/to/search
directory:
grep -r "my string" /path/to/search