• Home
  • Python
    • Introduction to Python
    • Python Developer
  • JavaScript
    • Introduction to JavaScript
    • JavaScript Developer
  • React.js
    • Introduction to React
    • React Developer
  • TypeScript
    • Introduction to TypeScript
    • TypeScript Developer
  • Linux Shell
    • Introduction to the Linux Shell
    • Linux Shell Developer
  • C++
    • Introduction to C++
    • C++ Developer
  • C Language
    • Introduction to C
    • C Developer
  • Rust
    • Introduction to Rust
    • Rust Developer
  • Zig
    • Introduction to Zig
    • Zig Developer
  • Interactive Training
  • Pricing
  • Brainstorm
STEMTrainingGrounds
  • Courses
    • Home
    • Python
      • Introduction to Python
      • Python Developer
    • JavaScript
      • Introduction to JavaScript
      • JavaScript Developer
    • React
      • Introduction to React
      • React Developer
    • TypeScript
      • Introduction to TypeScript
      • TypeScript Developer
    • Linux Shell
      • Introduction to the Linux Shell
      • Linux Shell Developer
    • C++
      • Introduction to C++
      • C++ Developer
    • C Language
      • Introduction to C
      • C Developer
    • Rust
      • Introduction to Rust
      • Rust Developer
    • Zig
      • Introduction to Zig
      • Zig Developer
  • Interactive Training
  • Pricing
  • Navigate
    • Home
    • Reading Grounds
    • Brainstorm

Quick Links

  • About Us
  • Pricing
  • Partnership
  • Brainstorm
  • Terms
  • Privacy
  • Refunds

Courses

  • Python
    • Introduction to Python
    • Python Developer
  • JavaScript
    • Introduction to JavaScript
    • JavaScript Developer
  • React
    • Introduction to React
    • React Developer
  • TypeScript
    • Introduction to TypeScript
    • TypeScript Developer
  • Linux Shell
    • Introduction to the Linux Shell
    • Linux Shell Developer
  • C++
    • Introduction to C++
    • C++ Developer
  • C Language
    • Introduction to C
    • C Developer
  • Rust
    • Introduction to Rust
    • Rust Developer

Newsletter

Subscribe to our free monthly newsletter, for a quick update on Python, JavaScript, and React news

© 2025 - 2026 STEMTrainingGrounds. All Rights Reserved.

Linux Shell Developer -

Lesson 3 of 35

Lesson Progress: 0%

Lesson Progress: 0%
Lesson Incomplete
← Previous: Linux find command
Lesson 3 of 35
Next: Linux sort command →

The grep command searches for patterns inside files. You give it a pattern and one or more files, and it prints every line that matches. Unlike find, which searches for filenames,grep searches file contents. Use grep when you need to find lines of text that match a specific word, phrase, or pattern.

  • grep "hello" file.txt prints every line infile.txt that contains hello.
  • The pattern is case-sensitive by default.
  • Only matching lines are shown, not the entire file.
  • grep is the standard tool for searching file contents in Linux.
  • grep -i "hello" file.txt performs a case-insensitive search.
  • The -i flag makes grep ignore uppercase and lowercase differences.
  • Lines containing hello, Hello, orHELLO will all match.
  • Case-insensitive search is useful when you are unsure of the exact capitalization.
  • grep -r "hello" . searches recursively through all files in the current directory.
  • The -r flag tells grep to descend into subdirectories.
  • Each match is shown with the filename and the matching line.
  • Recursive search is ideal for finding text across an entire project.
  • grep -v "hello" file.txt prints lines that do NOT match the pattern.
  • The -v flag inverts the match.
  • This is useful for excluding lines that contain a certain word.
  • Inverted matching works with all other grep options like-i and -r.
  • grep -c "hello" file.txt prints only the count of matching lines.
  • The -c flag stands for "count".
  • Instead of showing each matching line, it shows a single number.
  • Counting matches is useful for quick statistics on file contents.
  • grep -n "hello" file.txt shows matching lines with their line numbers.
  • The -n flag prefixes each match with its line number.
  • Line numbers help you locate matches in a file quickly.
  • You can combine -n with other flags like -iand -r.

Test Incomplete

What does grep do?

Question #

1/15

Score

0/0 - 0.0 %

Task Incomplete
Example
~$ grep "hello" file.txt
  • Run grep "hello" file.txt
Linux Shell
~$
Task Incomplete
Example
~$ grep -i "hello" file.txt
  • Run grep -i "hello" file.txt
Linux Shell
~$
Task Incomplete
Example
~$ grep -r "hello" .
  • Run grep -r "hello" .
Linux Shell
~$
Task Incomplete
Example
~$ grep -v "hello" file.txt
  • Run grep -v "hello" file.txt
Linux Shell
~$
Task Incomplete
Example
~$ grep -c "hello" file.txt
  • Run grep -c "hello" file.txt
Linux Shell
~$
Task Incomplete
Example
~$ grep -n "hello" file.txt
  • Run grep -n "hello" file.txt
Linux Shell
~$