grep

grep

grep is a search tool for text files: it scans line by line and outputs every line that matches a search pattern. On servers and in software development, it is the standard means of quickly finding relevant spots in huge log files.

grep is a small program that you start via a text input on the computer, rather than through a window with buttons. You give it two things: a search pattern and one or more files. grep then reads through the files line by line. Every line that matches the pattern it writes to the screen; all others it leaves out. You can think of it as a highlighter that flips through a book by itself and only copies out the matching lines. The program dates back to the early 1970s and today belongs to the standard toolkit of Linux and macOS.

Why a 50-year-old search program has survived

Computers constantly generate text records known as logs. Every web server writes down who accessed which page. Every app notes when something went wrong. Such files often have millions of lines, and no one reads them from the start. You need a tool that can pull the three interesting lines out of this mass.

That is exactly what grep does, and it does it very fast. For a few hundred megabytes of text, it often takes less than a second. A text editor would first have to load the entire file into memory and would simply freeze with large files. grep, by contrast, works through the file in small chunks and needs hardly any memory.

Then there is a second reason: the command can be automated. You can write it into a script that runs every night and raises an alarm when a particular error shows up. A human clicking around in a program window cannot do that. That is why grep remains, to this day, part of countless monitoring systems in data centers.

Search patterns instead of exact words

In the simplest case, you search for a fixed word. The command grep “error” logfile.txt shows all lines of the file logfile.txt in which the word error occurs. For many everyday cases, that is already enough.

The real strength, however, lies in flexible search patterns that experts call regular expressions. Here, certain special characters do not stand for themselves but for rules. A period, for example, means “any single character goes here.” An asterisk means “the character before it may repeat any number of times.” This way, you can search for all lines that start with a number, or for anything that looks like an email address.

In addition, short flags control the behavior. With -i, grep ignores upper and lower case; with -v, it reverses the search and shows all lines that do NOT match. With -r, it searches an entire folder including subfolders. A common misconception, by the way, is that grep searches whole files. It always searches line by line, and the line is also what gets output.

Where the command shows up in daily work life

Anyone working as a developer or system administrator often uses grep several times an hour. Typical questions: In which file of our program does this text actually appear? When did this user last log in? In security incidents too, it is the first tool used to comb through log files for suspicious access.

The word has even made its way into the industry’s everyday language. “Can you grep that?” simply means: search for that in the files. In job postings for IT roles, grep is frequently listed as a basic skill, taken just as much for granted as spreadsheet skills in office jobs.

It also plays a role in the context of AI. Anyone preparing huge text collections for training a language model uses it to filter out unwanted content or duplicates. And when an AI assistant searches through program code, it often calls upon this very old command in the background. There are now faster successors such as ripgrep, but the underlying principle has remained unchanged.

Subscribe free. Unsubscribe the second it sucks.

High-signal news across AI, business, UX, and tech. Every morning.