↑↓ move Enter open Esc close

How to Use grep for Case-Insensitive Search in Linux

Make grep match Error, ERROR and error with one option.

Case differences are a frequent source of missed matches. grep -i removes that problem for logs and other text.

Step by step

1 Search one file

$ grep -i "error" app.log

Matches common case variants of the term.

2 Combine with recursion

$ grep -rni "timeout" ./logs

Search a directory tree while ignoring case.

3 Count matches

$ grep -ic "warning" app.log

The -c option counts matching lines.

4 Show context

$ grep -i -B2 -A3 "fatal" app.log

Print nearby lines for troubleshooting.

Tips worth knowing

Frequently asked questions

What does grep -i mean?

It tells grep to ignore case while matching.

Can I combine it with recursion?

Yes: `grep -rin "pattern" directory/` is common.

The commands behind it

Concepts involved: Regular expression

More how-to guides