Beginner Package: grep

grep

Search text for lines matching a pattern.

Syntax

grep [options] pattern [file...]

Description

grep searches input (files, or piped from another command) for lines matching a pattern, using regular expressions by default, and is one of the most-used commands in any Linux troubleshooting workflow.

Examples

grep "error" /var/log/syslog
Find lines containing "error" in a log file
grep -i "error" file.log
Case-insensitive search
grep -r "TODO" ./src
Recursively search every file under a directory
grep -v "debug" file.log
Show only lines that do NOT match a pattern

Applies to

Ubuntu Debian Linux Mint RHEL CentOS / Rocky / AlmaLinux Fedora Arch Linux openSUSE Alpine Linux