Linux, terminal and Git

Stage 3 · Lesson 2 of 8

Searching text with grep

Text tools

searches text and prints the lines that match a pattern. A few cover daily use. -i ignores upper and lower case.

-n adds line numbers. -r searches a whole folder and everything inside it. -v shows the lines that do not match.

-l lists only the file names, -c counts matching lines and -E turns on extended . For example, grep -rn "TODO" src/ finds every TODO in src with its file and line. Inside a pipeline, grep filters the output of other commands. Many developers also install ripgrep (rg), which is faster and skips files ignores.

Common trapforgetting to quote a pattern that contains spaces or special characters.

A question to check yourself, an AI practice session and 1 cheat sheet entry come when you add the roadmap to your account. Add it

Resources for this stage

Start with· follow one of these

Practise

  • Test regular expressions on sample text with a plain explanation of each part

  • Middle levels need grep, sort, uniq and find to locate the next password

Keep handy

  • The official jq manual with examples for every filter

  • Quick examples for find, sed, awk and friends when you forget the syntax

Mark this stage as not done?