Day 17/ 30 Days of Linux Mastery: Grep Command
Table of Contents Introduction What is grep? Core grep Commands Real-World Scenario: Using grep Commands Conclusion Let's Connect Introduction Welcome back to day 17!. Today, we are talking about a core command in Linux, the grep command. When I think of grep I simply think of a filter. If you have ever needed to search for a word inside a file, filter logs, or analyze output from a command, grep is your go-to tool. Let’s get into it! What is grep? grep stands for Global Regular Expression Print. It searches for lines in a file or input that match a given pattern and prints them out. You can use it to: Search through config files Analyze logs Combine it with other commands to extract exactly what you need Core grep Commands Before we list the core grep commands, here is the basic syntax; grep [options] pattern [file...] Here are the grep commands and their use; grep Command Description -i Case-insensitive search -v Invert match (show lines that do not match) -r or -R Recursive search through directories -n Show line numbers of matches -c Count the number of matching lines -l List only the filenames that contain the match -e Use multiple patterns --color=auto Highlight the match in color for readability Real-World Scenario: Using grep Commands Let's say we have an error log file. We decide to filter the file and select only the lines with ERROR grep "ERROR" demologs.txt Show line numbers of the errors found grep -n "ERROR" demoerrorlog.txt Let's imagine there was a word 'error', but not in uppercase format. We want to filter for errors but make it case-insensitive. grep -i "error" demologs.txt Exclude Certain Matches grep -v "ERROR" demologs.txt - # Case-Sensitive grep -iv "error" demologs.txt - # Case-Insensitive Note: grep -v "error" This excludes all lines that contain the exact string "error" (case-sensitive). So, it will only remove lines that match "error" in lowercase. It will still show lines like "Error" or "ERROR". grep -iv "error" This adds the -i flag, which makes the search case-insensitive, so it excludes lines containing error, Error, ERROR, or any variation in letter case. The result is cleaner if you are trying to remove all forms of "error" regardless of case. Conclusion This is a job-ready skill. As a Linux or DevOps engineer, being able to search logs, filter noise, and pinpoint issues quickly with grep can save valuable time in production environments. If this is helpful to you, feel free to bookmark, comment, like and follow me for Day 18! Let's Connect! If you want to connect or share your journey, feel free to reach out on LinkedIn. I am always happy to learn and build with others in the tech space. #30DaysLinuxChallenge #Redhat#RHCSA #RHCE #CloudWhistler #Linux #Rhel #Ansible #Vim #CloudComputing #DevOps #LinuxAutomation #IaC #SysAdmin#CloudEngineer

Table of Contents
- Introduction
- What is
grep
? - Core
grep
Commands - Real-World Scenario: Using
grep
Commands - Conclusion
- Let's Connect
Introduction
Welcome back to day 17!. Today, we are talking about a core command in Linux, the grep
command.
When I think of grep
I simply think of a filter.
If you have ever needed to search for a word inside a file, filter logs, or analyze output from a command, grep
is your go-to tool.
Let’s get into it!
What is grep
?
grep
stands for Global Regular Expression Print. It searches for lines in a file or input that match a given pattern and prints them out.
You can use it to:
- Search through config files
- Analyze logs
- Combine it with other commands to extract exactly what you need
Core grep
Commands
Before we list the core grep
commands, here is the basic syntax;
grep [options] pattern [file...]
Here are the grep
commands and their use;
grep Command |
Description |
---|---|
-i |
Case-insensitive search |
-v |
Invert match (show lines that do not match) |
-r or -R
|
Recursive search through directories |
-n |
Show line numbers of matches |
-c |
Count the number of matching lines |
-l |
List only the filenames that contain the match |
-e |
Use multiple patterns |
--color=auto |
Highlight the match in color for readability |
Real-World Scenario: Using grep
Commands
- Let's say we have an error log file.
- We decide to filter the file and select only the lines with ERROR
grep "ERROR" demologs.txt
- Show line numbers of the errors found
grep -n "ERROR" demoerrorlog.txt
- Let's imagine there was a word 'error', but not in uppercase format. We want to filter for errors but make it case-insensitive.
grep -i "error" demologs.txt
- Exclude Certain Matches
grep -v "ERROR" demologs.txt - # Case-Sensitive
grep -iv "error" demologs.txt - # Case-Insensitive
Note:
grep -v "error"
This excludes all lines that contain the exact string "error" (case-sensitive).
So, it will only remove lines that match "error" in lowercase. It will still show lines like "Error" or "ERROR".
grep -iv "error"
This adds the -i flag, which makes the search case-insensitive, so it excludes lines containing error, Error, ERROR, or any variation in letter case.
The result is cleaner if you are trying to remove all forms of "error" regardless of case.
Conclusion
This is a job-ready skill. As a Linux or DevOps engineer, being able to search logs, filter noise, and pinpoint issues quickly with grep
can save valuable time in production environments.
If this is helpful to you, feel free to bookmark, comment, like and follow me for Day 18!
Let's Connect!
If you want to connect or share your journey, feel free to reach out on LinkedIn.
I am always happy to learn and build with others in the tech space.
#30DaysLinuxChallenge #Redhat#RHCSA #RHCE #CloudWhistler #Linux #Rhel #Ansible #Vim #CloudComputing #DevOps #LinuxAutomation #IaC #SysAdmin#CloudEngineer