grep -F (fgrep): Match Fixed Strings Literally
grep -F treats the pattern as a literal fixed string with no regex interpretation.
When the text you are searching for contains dots, slashes, or brackets, -F avoids having to escape them. It is also faster than regex matching.
What it does
grep -F (--fixed-strings) matches the pattern as a plain string, so characters like ., *, [, $, and \ are literal rather than regex metacharacters. The old fgrep command is the deprecated equivalent. Multiple fixed strings can be given one per line.
Common usage
# search for a literal path (dots and slashes are literal)
grep -F "/etc/app/config.yaml" install.log
# search for a literal version string
grep -F "v1.2.0-rc.3" releases.txt
# multiple literal strings
grep -F -e "10.0.0.1" -e "10.0.0.2" access.logOptions
| Flag | What it does |
|---|---|
| -F / --fixed-strings | Match the pattern literally, not as a regex |
| -e <pat> | Add a fixed string (repeatable) |
| -f <file> | Read fixed strings from a file, one per line |
| -w | Whole-word match of the literal |
| -x | Match only whole lines |
In CI
Use -F when comparing against config values, file paths, or version strings that contain dots and slashes; it removes a whole class of "why does my regex not match" bugs. It is also the fastest mode, which matters when scanning large logs.
Common errors in CI
Calling fgrep on recent GNU grep prints "fgrep: warning: fgrep is obsolescent; using grep -F"; switch to grep -F. If a literal search unexpectedly matches extra lines, you may have left -F off and a dot in your string matched any character. With -F, regex anchors like ^ are literal too, so use -x for whole-line matching instead.