Bash 5 reference · Text and System Tools

grep (Linux command)

Search files or input for lines matching a pattern, with options for case, counts, context, recursion and regex.

Bash 5

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

grep [OPTIONS] PATTERN [FILE...]

Parameters

ParameterDescription
-i Ignore case.
-v Invert the match.
-n / -c Line numbers / count.
-r / -l Recursive / list file names.
-E Extended regex.
-o Print only the matched part.
-q Quiet: just the exit status.

Examples

Case-insensitive and inverted
printf 'INFO up\nERROR db\nerror cache\n' > app.log
grep -in error app.log
grep -c -v -i error app.log

Output

2:ERROR db
3:error cache
1

Run this on your computer — see “Get Started” for setup.

Extract matches
echo 'order=42 total=19.99 order=7' | grep -oE 'order=[0-9]+'

Output

order=42
order=7

Run this on your computer — see “Get Started” for setup.

Was this page helpful?