LFCS Essential Commands Practice Question
A script needs to search for lines containing 'ERROR' in /var/log/syslog and count them. Which command pipeline achieves this?
⚠ Common exam trap
It's easy for candidates to choose `grep -c` (option D) because it achieves the same result, but the question specifically requires a pipeline, and Linux Foundation often tests the literal interpretation of 'command pipeline' to catch those who overlook the wording.
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 ERROR /var/log/syslog | wc -l
It uses `grep` to filter lines containing 'ERROR' from `/var/log/syslog` and pipes the output to `wc -l`, which counts the number of lines. This pipeline accurately counts the lines that match the pattern, which is the required task.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
wc -l /var/log/syslog
Why it's wrong here
wc -l /var/log/syslog counts all lines in the file, not just those containing ERROR. Incorrect.
- ✗
grep ERROR /var/log/syslog | wc -c
Why it's wrong here
grep ERROR /var/log/syslog | wc -c counts characters in the matched lines, not the number of lines. Incorrect.
- ✓
grep ERROR /var/log/syslog | wc -l
Why this is correct
grep ERROR /var/log/syslog filters lines containing ERROR and pipes them to wc -l, which counts those lines. Correct.
- ✗
grep -c ERROR /var/log/syslog
Why it's wrong here
grep -c ERROR /var/log/syslog also counts lines containing ERROR, but the question asks for a command pipeline. While functionally similar, it is not a pipeline per the literal requirement. Incorrect.
Go deeper
Related to this question
About these practice questions
One of 507 original LFCS 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 LFCS practice question is part of Courseiva's free Linux Foundation 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 LFCS exam.