Linux Basics for Hackers — Chapter 2: Text ManipulationText Manipulation · Lesson 1 of 2 · “Finding the needle: filtering streams with grep
Story page · ~4 min lesson

When a terminal gives you too much

Linux command-line tools are generous: they hand you the whole file, the whole log, the whole configuration. Most of the time you only care about the few lines that match a keyword. That is the job of grep — described in the source as probably the most widely used text manipulation command in Linux.

grep lets you filter the content of a file for display. Give it a keyword and a source of text, and it returns only the lines that contain that keyword. Everything else is hidden.

grep reads a stream of text and prints only the lines that match the keyword you give it.