How to search case-insensitively with grep

Log files, exports, and copied status text often mix uppercase and lowercase values even when the label means the same thing. Use grep -i when a search for error also needs to catch ERROR and Error without repeating the pattern.

The -i option tells grep to ignore case while matching the pattern. It does not change the text that prints, so the output still shows the original spelling from each matching line.

The sample below uses a small local log file with three differently cased error lines and two unrelated lines. The expected proof is that grep -i 'error' prints only the three error lines, while grep -in adds line numbers without changing the match set.

Steps to search case-insensitively with grep:

  1. Create a short sample file with mixed-case text.
    $ cat > app.log <<'EOF'
    INFO service ready
    error failed login for user api
    WARNING retry scheduled
    ERROR database timeout
    Error cache warmup failed
    EOF
  2. Search for the lowercase pattern while ignoring case.
    $ grep -i 'error' app.log
    error failed login for user api
    ERROR database timeout
    Error cache warmup failed

    grep prints the original line text. The uppercase and title-case matches prove that matching ignored letter case, not that the file was rewritten.

  3. Add line numbers when the matching file needs a direct handoff to an editor, ticket, or review note.
    $ grep -in 'error' app.log
    2:error failed login for user api
    4:ERROR database timeout
    5:Error cache warmup failed
  4. Search a different lowercase pattern to confirm the same option handles uppercase matches.
    $ grep -i 'timeout' app.log
    ERROR database timeout
  5. Remove the sample file after testing.
    $ rm app.log