What command searches for patterns in files?

The story behind the answer

The command that searches for patterns in files is `grep`.

The name comes from the classic Unix editor command `g/re/p`, meaning globally search for a regular expression and print matching lines. The standalone `grep` utility emerged from Unix work by Ken Thompson and became one of the most widely used tools in command-line text processing.

`grep` reads files or standard input and prints lines that match a supplied pattern. For example, `grep error server.log` searches one log file, while `grep -R TODO project/` searches recursively. GNU grep supports regular expressions, case-insensitive matching with `-i`, line numbers with `-n`, and inverted matches with `-v`.

A common mix-up is confusing `grep` with `find`. `find` locates files and directories by attributes such as name, size, or modification time; `grep` examines file contents. `sed` transforms text streams, while `awk` performs structured text processing. The related command `fgrep`, now commonly expressed as `grep -F`, searches fixed strings rather than regular expressions.

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: