Linux Tutorial - Grep Cheat Sheet logo

Linux Tutorial - Grep Cheat Sheet

Free

Quick reference for grep command and regex

FreeFree tier
Type
Open Source

About Linux Tutorial - Grep Cheat Sheet

A concise cheat sheet for the Linux grep command, covering basic flags (egrep, -i, -v, -w, -c, -l, -n, -r) and regular expression syntax including metacharacters, multipliers, and anchors. Includes practical examples for searching text files and matching patterns. Part of the Ryan's Tutorials Linux tutorial series, intended for users who already understand grep usage.

Key Features

Basic grep flags: egrep, -i (ignore case), -v (invert match), -w (whole words), -c (count), -l (filenames), -n (line numbers), -r (recursive)
Regular expression metacharacters: . (any char), [abc] (range), [^abc] (not range), () (grouping), | (OR), \ (escape)
Multipliers: ? (optional), * (zero or more), + (one or more), {n}, {n}, {n,m}
Anchors: ^ (line start), $ (line end), \< (word start), \> (word end), \b (word boundary)
Practical examples showing real-world usage (e.g., finding email addresses, matching patterns)

Pros & Cons

Pros
  • Comprehensive coverage of grep options and regex syntax
  • Includes multiple practical examples for clarity
  • Free and open source (part of standard Linux utilities)
  • Organized into clear sections (basic usage, regex, multipliers, anchors)
  • Part of a larger Linux tutorial ecosystem for deeper learning
Cons
  • Assumes prior knowledge of grep – not a beginner tutorial
  • Static web page without interactive practice or exercises
  • Limited to basic and intermediate regex – advanced topics not covered

Best For

Learning and practicing Linux command line text searchingFast reference for grep options and regex syntaxLog file analysis and pattern matchingTeaching or self-study of regular expressions in grep

FAQ

What is the difference between grep and egrep?
egrep is equivalent to grep -E and runs grep with extended regular expressions.
How do I ignore case when searching with grep?
Use the -i option to ignore case (uppercase/lowercase letters).
How can I count matching lines with grep?
Use the -c option to print a count of matching lines. Combine with -v to count non-matching lines.
What does the -v flag do?
The -v option returns all lines which do not match the pattern.
What does the asterisk (*) mean in grep regular expressions?
The asterisk (*) is a multiplier meaning the preceding item will be matched zero or more times.
How do I match a word boundary with grep?
Use \b to match either the beginning or end of a word.