fgrep — Fixed-string search
Linux / Basic Linux commands / fgrep.html
A grep variant that matches literal strings without regex interpretation.
Basic Information
| Command Name | fgrep |
|---|---|
| One-line Introduction | A grep variant that matches literal strings without regex interpretation. |
| Provided by | GNU grep |
| Official Documentation | https://man7.org/linux/man-pages/man1/grep.1.html |
| Supported Operating Systems | Linux, macOS (deprecated), BSD |
| Installation Status | Installed by default |
| Category | Linux basic commands (tags: Linux basic commands (tags: fgrep, grep, fixed string, literal)) |
What is this command?
fgrep behaves like grep -F and treats the pattern as a literal string rather than a regex. It is handy when the search text contains dots or brackets.
Modern GNU grep recommends grep -F. To search many literals at once, grep -F -f patterns.txt is convenient.
What problems does it solve?
- Searching values with dots such as IP addresses or versions
- Matching log text that contains brackets or asterisks
- Searching many literals from a list file
- Avoiding regex escaping entirely
Key features
Literal matching
Metacharacters are treated as plain characters.
- When to use: Finding values containing dots or brackets
- What you get: Exact matches without escaping.
- Limitations: Regex features are unavailable.
Pattern list
The -f option reads patterns from a file.
- When to use: Checking blocklists or keyword sets
- What you get: One invocation searches many strings.
- Limitations: Blank lines may match every line.
Performance
Literal search uses faster algorithms.
- When to use: Finding plain strings in large logs
- What you get: It is often faster than regex.
- Limitations: Case-insensitive search needs an extra flag.
Installation and usage
Check whether it is installed
fgrep --version
sudo apt install grep # Debian/Ubuntu sudo dnf install grep # Fedora
Real-world examples
Value with dots
Match an IP address literally.
fgrep '192.168.0.10' access.log
Search with a list
Read several strings from a file.
printf 'ERROR\nFATAL\n' > /tmp/p.txt
fgrep -f /tmp/p.txt app.log
Use grep -F
Run the same search with the recommended syntax.
grep -F '[main]' app.log