DEV Community

Dan Higgins
Dan Higgins

Posted on

Day 8: Let’s Get Greppy – Finding Text Like a Pro in RHEL 9

Alright, command-line comrades, it’s time we talk about someone very special…

Grep — the text detective that never sleeps.

If you’ve ever stared at a log file wondering if the answer to your issue is hiding somewhere in 3,000 lines of gobbledygook, grep is your new best friend.

📚 Table of Contents

So what exactly is grep?

Grep stands for Global Regular Expression Print, but don't let the fancy name scare you. It basically means: “Hey Linux, find this text for me, now, please and thank you.”

Basic Syntax:

grep "pattern" filename

Let’s say you have a file called shopping.txt and it looks like this:

apples
bananas
pineapples
chocolate bananas

Run this, and boom — it’ll spit out:

Image description

Handy Flags for Beginners:

  1. -i (ignore case)
  2. -n (show line number)
  3. -r (search recursively through directories)

Image description

Now it finds both “Banana” and “banana”, and shows which line they’re on. Pretty slick.

Real World Use:

  • Searching logs for errors:

Image description

  • Finding a user in /etc/passwd:

Image description

Mini Mission:

Create a file with different fruit names. Use grep to find your favorites. Bonus points for using -i and -n.

Why It Matters

In a real-world tech job, whether you’re a sysadmin or cloud wizard, you’ll often need to extract one crucial line from a sea of chaos.

Mastering grep saves time, energy, and possibly your sanity.

Top comments (0)