DEV Community

Cover image for The history behind "grep"'s name
Hamza Tamenaoul
Hamza Tamenaoul

Posted on • Edited on

The history behind "grep"'s name

Originally posted in my portfolio.

grep, a tool that is widely used in the Unix world, a tool that no one could live without. It's one of the first command to which every linux beginner is introduced from its start, so its function is no secret to no one. However, what's the history behind its weird name ?

The answer to this question requires us to go back to the early days of Unix, days of resource scarcity, may they be processing power or memory resources. Software developper of the time had to play by the rules and develop very light programs that get the job done. And one of those tools was the ed text editor. But this editor is nothing like the modern editor we have today (VIM looks like JetBrains IDEs next to it). To see a line of text from the text buffer you needed to type p preceeded by the line number. And for searching the buffer for an occurence of a regular expression we could use like in VIM /regularexpression. But for us to search for all the occurences and print them we'll use g/regularexpression/p, written simply g/re/p. And that's how the world grep was born.

The history of Unix is full of these stories. Amazing stories about those early days of computing.

Top comments (17)

Collapse
 
juliencornuwel profile image
Julien Cornuwel

Nice, I didn't know that one :-)
In the same vein, I was taught the story about 'dd' in school : the program makes a 'Carbon Copy' of a file. But 'cc' was already taken by the 'C Compiler'.
Not sure about the authenticity of the story, though.

Collapse
 
nssimeonov profile image
Templar++ • Edited

Funny, I always thought it comes from data duplication and I never even checked...

Collapse
 
hamza profile image
Hamza Tamenaoul

It's the same thing I've heard from a "GOTO 2013" talk. Giving the history of unix naming, it's very likely this is what happened.

Collapse
 
michaeltharrington profile image
Michael Tharrington

Haha, as an absolute beginner, I really appreciate this one. I'm taking the Command Line Crash Course in Learn Python The Hard Way and have a bunch of flash cards with different commands on them, grep included.

Anyway, I think I get the "p" part and "re" ... but, what's the deal with "g"?

Collapse
 
val_baca profile image
Valentin Baca

g matches all lines ("global")

In general, to see all lines matching the regular expression “re”, use g/re/p.

robots.thoughtbot.com/how-grep-got...

Collapse
 
michaeltharrington profile image
Michael Tharrington

Appreciate ya clearing that up for me. :-)

Collapse
 
jaquino94 profile image
Justin

Nice, need to utilize this tool more!

Just wanted to share this link:
Where GREP came from

It's a video of Brian Kernighan, a close colleague of Ken Thompson, explaining how grep came to be; it's pretty interesting because he mentions that Ken created grep overnight!

Collapse
 
magicleon94 profile image
Antonello Galipò

That's an interesting fact, thanks for sharing. I've never asked myself what grep could mean, I should start doing it more often when I use my CLI!

Collapse
 
ben profile image
Ben Halpern

Ha! I never bothered to look this up. I feel like I would have understood its purpose much better as a newbie had I been taught this off the bat. 😄

Collapse
 
avalander profile image
Avalander

Wow, I had no idea, thanks for sharing!

Collapse
 
benjaminblack profile image
Benjamin Black • Edited

Let's listen to the guy (bwk) who was actually present when it was invented talk about Where GREP Came From.

Collapse
 
shiling profile image
Shi Ling

Ohhhh, so that's how it is. I always thought it was meant to be "grab" but spelt in Ye Old English or something.

Collapse
 
garfbradaz profile image
Gareth Bradley

As a Windows guy transitioning to Linux, I find this fascinating indeed.

Collapse
 
annecalie profile image
Ana Lúcia

Wow, that's useful, sure is easier to remember the command knowing what it means.