LPIC-1 GNU and Unix Commands Practice Question
A user runs the command 'grep -E '^[[:space:]]*[^#]' /etc/ssh/sshd_config' and receives no output. Which statement best explains this result?
⚠ Common exam trap
The trap here is assuming that [[:space:]] matches newlines in grep, or that -E changes the pattern's meaning, when the real explanation is the file's content.
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
✓
The regular expression matches lines that start with optional whitespace followed by a non-# character, so no output means every non-empty line begins with # or is empty.
The command searches for lines that do not start with a comment character after optional whitespace. No output indicates that all non-empty lines begin with '#'. The -E flag does not alter the meaning of this pattern, and the character class [[:space:]] does not include newline in grep's line-oriented processing. The negation [^#] correctly excludes '#'.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
The caret ^ inside the bracket expression negates the set, so [^#] matches any character including #, making the pattern match all lines.
Why it's wrong here
The caret ^ negates the set only when it is the first character inside the brackets. In '[^#]', it is first, so it negates, meaning the set matches any character except '#'. This is correct behavior, not an error. If the pattern matched all lines, grep would produce output, but here it produces none.
- ✗
The character class [[:space:]] includes newline characters, so the pattern matches across multiple lines and produces no output.
Why it's wrong here
In POSIX character classes, [[:space:]] matches space, tab, newline, carriage return, form feed, and vertical tab. However, grep processes input line by line, so newline characters are not present in the pattern space. The class effectively matches spaces and tabs only within a line, so the pattern works as intended and does not span lines.
- ✓
The regular expression matches lines that start with optional whitespace followed by a non-# character, so no output means every non-empty line begins with # or is empty.
Why this is correct
The pattern '^[[:space:]]*[^#]' matches a line beginning with zero or more whitespace characters, then a character that is not '#'. If grep returns nothing, every line either is empty or has '#' as the first non-whitespace character. This is a valid conclusion about the file's content, assuming the file exists and is readable.
- ✗
The -E option enables extended regular expressions, but the pattern uses basic regex syntax, causing grep to fail silently.
Why it's wrong here
The -E option enables extended regular expressions, which support additional metacharacters like +, ?, and | without backslashes. The pattern used here is compatible with both basic and extended regex, so -E does not cause a failure. Grep would still match lines correctly; the absence of output is not due to regex dialect.
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 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.