What does 'grep' do?

QuestionsQuestions8 SkillsProDec, 24 2025
0116

Great question!

grep stands for Global Regular Expression Print. In simple terms: grep is a powerful tool used to search for specific text or patterns within files.

Think of it like the "Find" (Ctrl+F) feature in a text editor, but for the Linux command line.

How it works:

When you run grep, it looks through a file line by line. If it finds a line that matches the pattern you provided, it prints that entire line to your screen.

Examples from your current step:

  1. Basic Search:

    grep "lab" practice.txt

    This finds every line that contains the letters "lab" anywhere in it.

  2. Starting with a pattern (^):

    grep "^lab" practice.txt

    The ^ symbol tells grep to only show lines that start with "lab".

  3. Ignoring Case (-i):

    grep -i "lab" practice.txt

    By default, grep is case-sensitive (it distinguishes between "lab" and "LAB"). The -i option tells it to ignore the case, so it matches "lab", "Lab", and "LABEX".

In short, grep is the "go-to" tool in Linux whenever you need to filter through data or find specific information inside a document!

0 Comments

no data
Be the first to share your comment!