The History and Origins of the Unix grep Command
The Unix grep command, created by Ken Thompson before the fourth edition of Unix and named after the ed editor’s “g/re/p” syntax, first appeared in Version 4, later expanded by Al Aho into egrep and fgrep, and was popularized through the GNU and BSD implementations, illustrating Unix’s collaborative evolution.
grep is a classic Unix command‑line utility that searches input files for lines matching a given pattern. It was written by Ken Thompson, the co‑creator of Unix, and first appeared in Unix Version 4, although the original man page lacked many of the options we know today.
The Unix v6 man page for grep looks like this:
NAME
grep - search a file for a pattern
SYNOPSIS
grep [ -v ] [ -b ] [ -c ] [ -n ] expression [ file ] ...
DESCRIPTION
Grep searches the input files (standard input default) for lines matching the regular expression. ...
SEE ALSO
ed (I), sh (I)Later, a bug note added that lines longer than 256 characters were truncated.
There has been confusion about grep’s “birthday”. Some sources cite the date 3/3/1973 from the Unix v4 man page, but this is likely the last‑modified date of the manual, not the creation date of the command. In a 2014 email, Ken Thompson wrote that he does not remember the exact date and that grep existed “sometime before the 4th edition”.
Ken also explained that grep was originally a private tool of his before he made it public, and that the name comes from the ed command g/re/p (global regular expression print).
Other contributors added to the grep family. Al Aho, a Bell Labs researcher and co‑author of AWK, wrote egrep and fgrep in 1975, extending grep with full regular‑expression support and faster matching for simple patterns. These utilities were later merged into a single command, with modern usage employing the -E and -F options for POSIX‑compatible extended and fixed‑string matching.
Example usage of the original ed editor to demonstrate grep‑like behavior:
$ ed /etc/passwd
699
g/bash/p
root:x:0:0:root:/root:/bin/bash
brm:x:1000:100::/home/brm:/bin/bash
git:x:619:619:git daemon user:/:/bin/bash
$ fgrep, egrepOn modern systems, the GNU implementation of grep (written by Mike Haerkal and first released around 1988) is the default on Linux, while BSD grep is common on macOS and other platforms. The GNU project announced grep in a 1987 bulletin, and the tool has been continuously improved and ported.
Overall, grep’s evolution—from Ken Thompson’s original utility to the extended egrep/fgrep variants and the GNU implementation—illustrates the collaborative and incremental nature of Unix tool development.
Baidu Tech Salon
Baidu Tech Salon, organized by Baidu's Technology Management Department, is a monthly offline event that shares cutting‑edge tech trends from Baidu and the industry, providing a free platform for mid‑to‑senior engineers to exchange ideas.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.