Courseiva

LPIC-1 Shells, Scripting and Data Management Practice Question

An administrator wants to list all lines in a log file that do NOT contain the word 'ERROR'. Which command should be used?

⚠ Common exam trap

Watch out — candidates often confuse the `-v` invert-match flag with other common flags like `-i` (case-insensitive) or `-w` (whole-word), or simply forget that `grep` by default shows matching lines, not excluding them.

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 -v 'ERROR' logfile

The `-v` flag inverts the match, causing `grep` to output only lines that do NOT contain the pattern 'ERROR'. This is the standard way to exclude lines matching a pattern in a file.

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 -i 'ERROR' logfile

    Why it's wrong here

    grep -i performs case-insensitive matching, so it prints lines containing ERROR instead of omitting them. It is tempting because it broadens pattern matching, but it is designed to ignore letter case, not to select non-matching lines as -v does.

  • ✗

    grep -w 'ERROR' logfile

    Why it's wrong here

    grep -w matches whole words containing ERROR, so it still prints those lines rather than excluding them. It is tempting because -w refines matching precision, but it is designed to anchor word boundaries, not to invert the match as -v does.

  • ✓

    grep -v 'ERROR' logfile

    Why this is correct

    grep -v inverts the match, printing every line that does not contain the pattern 'ERROR'. The pattern is treated as a basic regular expression, and unmatched lines pass through unchanged, which directly satisfies the requirement to list all non-matching lines from the log file.

  • ✗

    grep 'ERROR' logfile

    Why it's wrong here

    grep 'ERROR' logfile prints every line containing ERROR, the exact opposite of the requirement. It is tempting because it correctly identifies the target pattern, but it is designed to select matching lines, whereas -v inverts the selection to exclude them.

About these practice questions

This LPIC-1 question is part of Courseiva's 402-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

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.