Skip to main content

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)

FlagDescription
-i, --ignore-caseIgnore case distinctions.
-v, --invert-matchSelect non-matching lines.

Real-world Examples

  1. 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.)

  2. Search for multiple fixed strings (if pattern contains newlines):

    fgrep -f words_to_find.txt large_log_file.txt