fgrep

fixed-string search without regex

TLDR

Search for literal string
$ fgrep "[search string]" [file.txt]
Search multiple files
$ fgrep "[pattern]" [file1.txt] [file2.txt]
Case insensitive search
$ fgrep -i "[pattern]" [file.txt]
Show line numbers
$ fgrep -n "[pattern]" [file.txt]
Recursive search
$ fgrep -r "[pattern]" [directory]

SYNOPSIS

fgrep [options] pattern [files...]

DESCRIPTION

fgrep searches for fixed strings rather than regular expressions. It's equivalent to grep -F and is faster when searching for literal text without regex metacharacters.The tool treats the pattern as a plain string, so characters like ., *, and [ have no special meaning. This makes it ideal for searching log files, code, or any text containing regex metacharacters.fgrep is particularly useful when the search pattern comes from user input or variables that might contain special characters.

PARAMETERS

PATTERN

Fixed string to search for.
FILES
Files to search.
-i, --ignore-case
Case insensitive matching.
-n, --line-number
Show line numbers.
-r, --recursive
Search directories recursively.
-l, --files-with-matches
Show only filenames.
-c, --count
Count matching lines.
-v, --invert-match
Show non-matching lines.
--help
Display help information.

INSTALL

sudo apt install grep
sudo dnf install grep
sudo pacman -S grep
sudo apk add grep
sudo zypper install grep
brew install grep

CAVEATS

No regex support by design. Deprecated in favor of grep -F; GNU grep 3.8 (2022) and later print a deprecation warning when invoked as fgrep. Multiple patterns require the -f option.

HISTORY

fgrep (fast grep) originated in Unix Version 7 as an optimized grep variant for literal strings. Modern implementations typically link to grep with the -F flag.

SEE ALSO

grep(1), egrep(1), rg(1)

RESOURCES

Homepage