grep is a command line utility originally written for use with the Unix operating system. The default behaviour of grep takes a regular expression on the command line, reads standard input or a list of files, and outputs the lines containing matches for the regular expression.
The name comes from a command in the Unix text editor ed that takes the form:
which means "search globally for lines matching the regular expression, and print them". There are various command line switches available when using grep that modify the default behaviour.
Other (incorrect) backronyms of the name exist, including: General Regular Expression Parser, General Regular Expression Print, Global Regular Expression Parser, and Global Regular Expression Print.
Many other commands contain the word "grep." pgrep, for instance, displays the processes whose names match a regular expression.
In Perl, grep is a built-in function, which when provided both a regular expression (or a general code block) and a list, it returns the elements of that list matched by the expression.
The word "grep" has also become a synonym for regular expressions themselves. Many text and word processors now employ regular expression search features, which those applications will often refer to as a "grep tool" or "grep mode" in which one creates "grep patterns", causing confusion, especially in non-Unix environments.
To output all lines not containing the string "foo", use "-v":
To output only the names of the matching files, use "-l":
To output all matching lines in the given list or files or directories, or recursively into their subdirectories ("." represents the current directory), use "-r":
Grep also can read from standard input. Use ps -ef to list all running processes combined with grep $USER to output all lines with your username in them. (So you print out all the processes you are running.)
Unix software | GNU project software
Grep | Grep | grep | grep | Grep | Grep | Grep | grep | Grep | Grep | Grep