Searching with grep

Start in your lab: cd /lab/pipelines.

grep PATTERN FILE prints every line of FILE that contains PATTERN. Its flags reshape the question:

  • -c: how many lines match?
  • -v: show the lines that don't match.
  • -i: ignore case, so alert finds ALERT.
  • -n: prefix each match with its line number.
grep alice guild.log
grep -c bob guild.log
grep -v login guild.log

Real world: grep -i error /var/log/syslog is step one of nearly every investigation. The pattern is a regular expression, so grep '^2026-03-01 23' finds everything from 23:00 on.