If you’re a Linux user, you must have probably come across the oddly-named Grep utility to search for patterns in files or piped output from commands. You may wonder where the program got its name.
This article will explain grep’s origins along with some brief information on the role of Grep in modern Linux culture.
Grep’s Origins at Bell Labs
Like many other modern Linux tools, Grep is a descendent of the original Unix system developed at Bell Labs in the 1970s.
Brian Kernighan, a Bell Labs computer scientist back then, now teaching at Princeton University, explains the origins of Grep in a Computerphile video.
Kernighan’s colleague, Ken Thompson, one of the inventors of Unix, was helping a fellow coworker do some textual analysis on The Federalist Papers, which were published under a pseudonym, to determine the authorship.
In the early 1970s, the Unix programmers at Bell Labs had a Digital PDP-11, where 64 kilobytes was considered luxurious. They also used slow Teletype machines, which utilized line editors to edit text. Ken had already written his own program that allowed text searching by using regular expressions.
Thompson packaged these text searching features into his own utility. Because this utility globally searches lines for regular expressions and prints them, it became “Global Regular Expression Print,” or simply Grep.
Kernighan also interviewed Ken Thompson at VCF East in 2019, and Thompson had an amusing anecdote about grep’s creation. Thompson’s boss, Doug McIlroy, approached him about the need for a text searching utility. Thompson promised to work on it overnight, but really only spent about an hour fixing bugs, since he’d already written Grep and had been using it privately. He presented it to McIlroy the next day. And the rest is history.
Grep’s Role in Linux Culture Today
Grep is still important to modern Linux culture, even though Linux doesn’t use any Unix code. GNU Grep is the most used version of Grep, as it comes preinstalled in almost every Linux distribution.
You can use Grep to search for a text pattern in a file:
grep pattern file
Or you can search for patterns in a piped output:
ps | grep '.*sh'
The ps command prints all the processes that are currently running on the system. Grep will search for lines in the output that are followed by sh, or running shells in practical terms.
Since the normalization of electronic documentation, programmers prefer having a utility that allows them to search for patterns in text files. They even refer to the lack of search in printed documentations by humorously saying “You can’t grep dead trees.” They have also termed the act of physically searching for things as visual grep or vgrep. This shows how much Grep permeates modern Linux and the computer science culture in general.
Get Out and Grep!
Now that you know where the Grep name comes from, you’ll be able to Grep some great things on your own as you expand your Linux knowledge.
Grep is one of the many commands that will help you in getting comfortable with Linux. Learning new commands should be of prime importance if you have decided to use Linux as your main operating system.