XK0-006 System Management Practice Question
A Linux administrator wants to search for the pattern 'ERROR' in all files under /var/log, ignoring case, and display line numbers. Which THREE options should be used with the grep command? (Select THREE).
⚠ Common exam trap
XK0-006 often tests grep flag selection in multi-select questions — candidates include -c or -v because they are common flags, but only -i, -n, and -r match the three stated requirements (case-insensitive, line numbers, recursive).
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
✓
-i
Option B (-i) is correct because it makes grep perform a case-insensitive match, so 'ERROR', 'error', and 'Error' are all found as required. Option D (-n) is correct because it prefixes each matching line with its line number, satisfying the requirement to display line numbers. Option E (-r) is correct because it recursively searches all files under the /var/log directory tree, which is needed to cover 'all files under /var/log'. Option A (-c) is not appropriate because it only counts matching lines instead of displaying them, and Option C (-v) is wrong because it inverts the match to show non-matching lines rather than the 'ERROR' pattern.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
-c
Why it's wrong here
The -c option suppresses matching lines and prints only a count per file, so it cannot display the requested lines or their numbers. It would be the correct choice when the administrator only needs the number of matches, whereas -i and -n satisfy the case-insensitive, line-numbered requirement.
- ✓
-i
Why this is correct
The `-i` flag makes grep match case-insensitively, so lines containing 'error', 'Error' or 'ERROR' are all returned. This directly satisfies the stem's requirement to search for the pattern 'ERROR' while ignoring case, rather than matching only uppercase occurrences.
- ✗
-v
Why it's wrong here
The -v option inverts the match, printing lines that do not contain ERROR, which is the opposite of the requirement. It would be correct when excluding matching lines, for example filtering out noise from a log, whereas -i and -n deliver the case-insensitive, line-numbered search requested.
- ✓
-n
Why this is correct
The -n flag prefixes each matching line with its line number within the file, directly satisfying the requirement to display line numbers alongside matches. Combined with -r for recursive traversal of /var/log and -i for case-insensitive matching of 'ERROR', it completes the three-flag set the scenario demands.
- ✓
-r
Why this is correct
The `-r` flag makes grep recurse through every subdirectory of /var/log, satisfying the requirement to search all files beneath that path rather than only those in the top level. Without it, grep would inspect just the named directory's immediate contents, missing nested log files entirely.
Go deeper
Related to this question
About these practice questions
One of 781 original XK0-006 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 and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official CompTIA exam blueprint
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.