Linux Terminal Command: fgrep

The fgrep command is an essential tool in Text Processing & Piping. In this tutorial, we will explore what fgrep does, look at everyday examples, and cover advanced options to supercharge your command-line workflow.


Concept & Explanation

The fgrep command is a wrapper for grep -F. It treats patterns as a list of fixed strings rather than regular expressions, making it faster when searching for literals like IP addresses or URLs.


Common Options & Syntax

fgrep [options] [arguments]

Here are the most common flags used with fgrep:


1. Interactive Example (Simple)

Here is how most people run the command:

# Example
fgrep '192.168.1.1' auth.log

What it does: Searches for the literal IP address ‘192.168.1.1’ in ‘auth.log’.


2. Power-User Example (Advanced)

For scripting and advanced diagnostics, use this configuration:

# Advanced
fgrep -f patterns_list.txt target.txt

What it does: Reads search strings from ‘patterns_list.txt’ line by line and matches them against ’target.txt’.


⚙️ Warning & Common Pitfalls

[!WARNING] fgrep is deprecated. Use grep -F instead to ensure compatibility with modern POSIX systems.


Here are some related posts on cli_tty1 you might want to check out: