XK0-006 System Management Practice Question
A technician needs to search a log file for lines containing either 'ERROR' or 'FATAL' and display the line numbers. Which command accomplishes this?
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 -n -E 'ERROR|FATAL' logfile
grep -n -E 'ERROR|FATAL' logfile uses extended regex with alternation and -n for line numbers. -i ignores case, but the stem does not mention case-insensitive; -v inverts match; -r is recursive.
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 -E 'ERROR|FATAL' logfile
Why it's wrong here
The -v flag inverts the match, printing lines that do not contain ERROR or FATAL, and no -n flag is present to display line numbers. It is tempting because -E correctly enables alternation, but inversion produces the opposite result from the required matching lines.
- ✗
grep -r -n 'ERROR|FATAL' logfile
Why it's wrong here
Without -E, grep treats the pipe as a literal character, so it matches the string 'ERROR|FATAL' rather than either word; -r also recurses directories unnecessarily. It is tempting because -n correctly prints line numbers, and the pattern syntax would work if extended regular expressions were enabled.
- ✓
grep -n -E 'ERROR|FATAL' logfile
Why this is correct
grep -n prints line numbers, and -E enables extended regular expressions so the alternation ERROR|FATAL matches either pattern. This satisfies the requirement to find lines containing either term while displaying their line numbers in the log file.
- ✗
grep -i 'ERROR|FATAL' logfile
Why it's wrong here
Without -E, the pattern 'ERROR|FATAL' is treated as a basic regular expression, so the pipe matches a literal character rather than alternation, and -n is absent so line numbers are not printed. It is tempting because -i is a valid flag, but it only ignores case, not the missing extended-regex and numbering flags.
Go deeper
Related to this question
About these practice questions
This XK0-006 question is part of Courseiva's 781-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 →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This XK0-006 practice question is part of Courseiva's free CompTIA 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 XK0-006 exam.