Grep

Grep is a command-line utility for Unix used for searching text documents. It can perform basic searches and advanced pattern matching using regular expressions. The grep utility is included with all major Unix distributions, including Linux and Mac OS X.

Grep can be run by simply typing grep at the command prompt. The command requires specific parameters, including the string to be located and the filename of the file to be searched. For example, if you want to check if the file "readme.text" has the word "license" in it, you would type the following command:

grep license readme.txt

If the word is not found, grep will not produce any output. If the string is located in the document, grep will list each occurrence of the string. If you need to perform a more complex search, you can use a regular expression. For example, the command below will search the file "us.txt" and list all lines that begin with "Me" or end with "you" (case-sensitive).

grep -E "^Me|you$" us.txt

The "-E" parameter in the example above indicates the pattern is an "extended regular expression." By using this option, you can make sure grep processes your search pattern as a regular expression instead of a basic string. Grep also supports several other command-line options, which can be used to create more specific queries and customize the output. You can view these options and learn more about grep by typing "man grep at the Unix command prompt.

NOTE: The name "grep" is an acronym that comes from the phrase, "Globally search a regular expression and print."

Updated September 2, 2013 by Per C.

quizTest Your Knowledge

Linux uses inodes to store information about what?

A
Peripheral devices
0%
B
Installed applications
0%
C
Network connections
0%
D
Individual files
0%
Correct! Incorrect!     View the Inode definition.
More Quizzes →

The Tech Terms Computer Dictionary

The definition of Grep on this page is an original definition written by the TechTerms.com team. If you would like to reference this page or cite this definition, please use the green citation links above.

The goal of TechTerms.com is to explain computer terminology in a way that is easy to understand. We strive for simplicity and accuracy with every definition we publish. If you have feedback about this definition or would like to suggest a new technical term, please contact us.

Sign up for the free TechTerms Newsletter

How often would you like to receive an email?

You can unsubscribe or change your frequency setting at any time using the links available in each email.

Questions? Please contact us.