GNU grep
The GNU implementation of grep.
grep matches lines against fixed strings (-F), basic regular expressions (default), or extended regular expressions (-E) in files or on standard input. The output is the matching lines, optionally with line numbers, file names, and surrounding context. The GNU implementation is unusually fast for the regex case, thanks to a finely tuned Boyer-Moore-derived matching engine that avoids running the regex backtracker on most input.
Mike Haertel wrote the original GNU grep in 1988, drawing on ideas from the AT&T grep that had been around since the early 1970s. The classic anecdote is Haertel's note that GNU grep "avoids looking at every input byte" by skipping over input that cannot possibly match — a clever optimisation that has shaped expectations of how fast a grep should be.
GNU grep ships preinstalled on every Linux distribution. macOS uses BSD grep, which is generally slower; users who want GNU behaviour install ggrep through Homebrew. ripgrep (rg) is the modern Rust replacement that has overtaken grep for many recursive search workloads.
Install
Already preinstalled on Linux. macOS ships BSD grep; for GNU grep: brew install grep
Authors
- Mike Haertel (creator of GNU grep)
- GNU Project