fgrep
Explanation
The fgrep command is equivalent to grep -F. It treats the pattern as a list of fixed strings, separated by newlines, rather than regular expressions. This makes it faster than standard grep when you need to search for exact strings that might contain characters that would normally be interpreted as regex metacharacters (like *, [, .). Note that fgrep is deprecated in favor of grep -F.
Basic Syntax
fgrep [OPTION]... PATTERNS [FILE]...
Common Flags and Options
(Shares most options with standard grep)
| Flag | Description |
|---|---|
-i, --ignore-case | Ignore case distinctions. |
-v, --invert-match | Select non-matching lines. |
Real-world Examples
-
Search for an exact string containing special characters:
fgrep "if [ \$a == 1 ]; then" script.sh(With standard grep, the brackets and dollar sign would be treated as regex characters unless escaped.)
-
Search for multiple fixed strings (if pattern contains newlines):
fgrep -f words_to_find.txt large_log_file.txt