LPIC-1 Shells, Scripting and Data Management Practice Question
A system administrator wants to display all lines in /var/log/syslog that do NOT contain the string 'error'. Which command accomplishes this?
⚠ Common exam trap
Many candidates confuse `-v` (invert match) with `-i` (case-insensitive) or `-r` (recursive), leading them to select options that still show matching lines instead of 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' /var/log/syslog
The `grep -v` option inverts the match, displaying only lines that do NOT contain the pattern. Therefore, `grep -v 'error' /var/log/syslog` outputs all lines from the file that lack the string 'error', which directly fulfills the requirement.
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 -v 'error' /var/log/syslog
Why this is correct
`grep -v` inverts the match, printing only lines that fail the pattern test, so every line lacking "error" is emitted while matching lines are suppressed. This directly satisfies the stem's requirement to display non-matching lines from /var/log/syslog, with the file passed as grep's final operand.
- ✗
grep -r 'error' /var/log/syslog
Why it's wrong here
The -r flag makes grep recurse through directories, so it searches contents of files under a path rather than inverting matches within one file. It is tempting because recursive searching is correct when hunting a string across an entire directory tree, but here a single named file needs -v to exclude matching lines.
- ✗
grep -l 'error' /var/log/syslog
Why it's wrong here
The -l flag lists only the names of files containing a match, so it prints /var/log/syslog rather than any lines, and it selects matching lines instead of excluding them. It is tempting as a grep variant, but inverting the match requires -v, as in grep -v 'error' /var/log/syslog.
- ✗
grep -i 'error' /var/log/syslog
Why it's wrong here
The -i flag only makes matching case-insensitive; it still prints lines containing 'error', the opposite of the requirement. It is tempting because case-insensitive searching is genuinely useful when log entries vary in capitalisation, but inverting the match needs -v, as in grep -v 'error'.
Go deeper
Related to this question
About these practice questions
One of 402 original LPIC-1 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
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.