Courseiva

LPIC-1 Shells, Scripting and Data Management Practice Question

A user needs to find all lines in a file that contain the word `error` while ignoring case, and also print the line number for each match. Which TWO `grep` invocations accomplish this? (Choose two.)

⚠ Common exam trap

The trap here is that `-c` and `-l` look like they add useful information, but they replace the normal matching-line output instead of supplementing it.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

grep -in error file.log

Case-insensitive matching is enabled by `-i`, and line numbers are added by `-n`. Whether written as `-in` or as separate `-i -n` options, both forms satisfy the requirement to list matching lines with their line numbers. The other options invert the match, print only a count, or print only filenames, none of which meets the stated goal.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    grep -l -i error file.log

    Why it's wrong here

    The `-l` option prints only the names of files containing at least one match, not the matching lines themselves. Although `-i` enables case-insensitive matching, the output is just the filename. This does not provide line numbers or the matching line content as required.

  • ✗

    grep -c -n error file.log

    Why it's wrong here

    The `-c` option suppresses normal output and prints only a count of matching lines. When `-c` is present, `-n` has no visible effect because individual lines are not printed. The user would receive a number rather than the matching lines with their line numbers.

  • ✓

    grep -in error file.log

    Why this is correct

    The `-i` option makes matching case-insensitive, and `-n` prefixes each matching line with its line number. Combined in `-in`, both requirements are met in a single concise invocation. This is the conventional short-option form and works on all POSIX-compatible grep implementations.

  • ✗

    grep -v -n error file.log

    Why it's wrong here

    The `-v` option inverts the match, selecting lines that do NOT contain the pattern. With `-n`, line numbers are printed for those non-matching lines. This is the opposite of what the scenario requires, so it fails to list the lines containing `error`.

  • ✓

    grep -i -n error file.log

    Why this is correct

    Options may be given separately, so `-i` and `-n` have the same effect as the combined `-in` form. Case-insensitive matching is enabled and line numbers are printed, satisfying both requirements. This separated form is equally valid and often preferred for readability in scripts.

About these practice questions

Courseiva writes every LPIC-1 question from scratch — 402 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official LPI exam blueprint

This LPIC-1 practice question is part of Courseiva's free LPI certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the LPIC-1 exam.