Frequently Asked Question

What is grep and why is its name so strange?

grep is the canonical Unix search tool: it reads files or standard input and prints every line that matches a pattern. The name comes from the old ed line editor, where the command g/re/p meant globally, regular expression, print; apply the pattern to every line and print the matches. Ken Thompson lifted that command out of ed into a standalone program in 1973, and the name stuck.

In day-to-day use, grep "error" /var/log/syslog is the standard sysadmin reflex for finding interesting lines in a log. Add -i for case-insensitive, -n to include line numbers, -r to recurse into directories, -v to invert the match, -c to count, or -C 3 to show three lines of context around each hit. Almost every other text-searching tool you will ever use, ack, ag, ripgrep, the search box in your editor, is some descendant of the same idea.

Video

Further reading and video