🧀 Learn Linux

Commonly used · Reading and processing text

grep: Filter text by pattern

Put in free practice

Syntax

grep [parameter] mode [file…]

Options

-i
Ignore case
-n
Show line number
-v
Reverse filtering
-c
Count matching rows
-r / -R
Search files recursively
-E
extended mode
-F
fixed string
-l
Show only matching files
-e
Specify mode

Examples

grep -n ERROR logs/app.log

Usage and sandbox support

The exit code for no match is 1. The sandbox uses the JavaScript regular subset, which is not exactly equivalent to GNU grep.

Hands-on exercises

Full documentation ↗

Related commands