egrep and fgrep
LINUXLPIC1-101
2/28/2026


1. The Definitions
egrep (Extended GREP): This version supports Extended Regular Expressions (ERE). It recognizes special metacharacters like |, +, ?, and () without needing to escape them with backslashes.
fgrep (Fixed/Fast GREP): This version treats your pattern as a fixed string, not a regular expression. It does not recognize any special characters; it looks for the exact literal characters you typed.
2. Key Technical Differences
Feature egrep (grep -E) fgrep (grep -F)
Pattern Type Extended Regular Expression Literal/Fixed String
Speed Fast, but processes complex logic Very fast for simple, large strings
Special Chars *, +, ?, `, ()` are active
Use Case Complex pattern matching Searching for exact phrases or IP addresses
3. Practical Examples
Imagine you are looking for a string that contains a period and a plus sign, like an IP range or a specific versioning tag.
Using egrep
If you search for 192.168.1.1+, egrep thinks:
. means "any character."
+ means "one or more of the previous character."
Result: It will match "192x168y1z11111", which is probably not what you want. You would have to escape them: 192\.168\.1\.1\+.
Using fgrep
If you search for 192.168.1.1+, fgrep thinks:
"I am looking for exactly these characters in this order."
Result: It only matches that exact string. No escaping required.
4. The Modern Way
In modern Linux systems, egrep and fgrep are actually considered deprecated. While they still work for backward compatibility, the "correct" way to use them now is by using flags with the standard grep command:
Instead of egrep, use grep -E
Instead of fgrep, use grep -F
Example: search two different IPs at the same time
If you don't want to mess with regex at all and just want to match two exact strings, you can use the -e flag multiple times.
grep -F -e "192.168.1.1" -e "10.0.0.5" access.log
Why use this? It’s the easiest to read. Because we used -F, we don't even have to escape the dots!
Confused about globbing and regex? Here is some background.
Contact
hello@unixtips.eu
© 2025. All rights reserved.