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
- Use -w for whole-word matching.
- Use -F for literal text.
- Locale settings can affect non-ASCII case handling.
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
Find lines matching a pattern in files or piped input — the workhorse of text search.
catPrint file contents, number lines, and join multiple files together.
Concepts involved: Regular expression
More how-to guides
See how much space is left, and find out what is using it.
Extract a .tar.gz archiveUnpack tar.gz, tar.bz2, tar.xz and zip archives from the command line.
Free a port that is already in useFind which process holds a port and stop it cleanly.
Find and replace text in filesReplace text in one file or across a whole project, safely.