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

grep

Find lines matching a pattern in files or piped input — the workhorse of text search.

cat

Print file contents, number lines, and join multiple files together.

Concepts involved: Regular expression

More how-to guides

Check disk space in Linux

See how much space is left, and find out what is using it.

Extract a .tar.gz archive

Unpack tar.gz, tar.bz2, tar.xz and zip archives from the command line.

Free a port that is already in use

Find which process holds a port and stop it cleanly.

Find and replace text in files

Replace text in one file or across a whole project, safely.