Courseiva
Essential CommandshardMultiple ChoiceObjective-mapped

LFCS Essential Commands Practice Question

A system administrator runs 'grep -r 'error' /var/log' and gets many false positives. They want to search only for the exact word 'error' as a whole word, case-insensitively, and display line numbers. Which command should they use?

⚠ Common exam trap

The trap here is that candidates often forget the `-w` flag is needed for whole-word matching, assuming `-i` alone is sufficient, or they confuse the order of flags and omit one of the required options.

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 -rwin 'error' /var/log

It combines all required flags: `-r` for recursive search, `-w` for whole-word matching (using word boundaries), `-i` for case-insensitive search, and `-n` for displaying line numbers. The `-w` flag ensures that only the exact word 'error' is matched, not substrings like 'error404' or 'error-prone', which eliminates false positives.

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 -rwi 'error' /var/log

    Why it's wrong here

    Missing -n for line numbers.

  • grep -rin 'error' /var/log

    Why it's wrong here

    No whole word matching.

  • grep -rwn 'error' /var/log

    Why it's wrong here

    Missing -i for case-insensitivity.

  • grep -rwin 'error' /var/log

    Why this is correct

    Correct: recursive, whole word, case-insensitive, line numbers.

About these practice questions

Courseiva writes every LFCS question from scratch — 507 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

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.