Courseiva
Essential Commands →mediumMultiple Choice

LFCS Essential Commands Practice Question

A security analyst needs to search for the literal string 'error: failed to connect' in all .log files under /var/log, including subdirectories. The search should be case-insensitive and display line numbers. Which command should they use?

⚠ Common exam trap

The trap here is assuming that a shell glob like /var/log/*.log works recursively; it does not, so --include is needed.

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 -rin "error: failed to connect" /var/log --include='*.log'

To recursively search only .log files with case-insensitivity and line numbers, use grep with -r, -i, -n, and --include. The --include='*.log' ensures only files with that extension are processed, while -r traverses subdirectories. This combination meets all stated requirements.

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 -rin "error: failed to connect" /var/log/*.log

    Why it's wrong here

    The wildcard /var/log/*.log expands only to .log files directly in /var/log, not subdirectories. Although -r is present, the shell expands the glob before grep runs, so recursive search does not apply to subdirectories. This misses .log files in nested directories.

  • ✗

    grep -rin "error: failed to connect" /var/log --exclude='*.log'

    Why it's wrong here

    The --exclude option does the opposite of what is needed: it skips files matching '*.log'. This would search all files except .log files, which is incorrect. The -r, -i, and -n flags are correct, but the exclusion defeats the purpose.

  • ✗

    grep -rl "error: failed to connect" /var/log

    Why it's wrong here

    The -l option lists only filenames containing matches, not the matching lines themselves. It also does not show line numbers. While -r is recursive, the absence of -i makes it case-sensitive, and without --include it searches all file types, not just .log files.

  • ✓

    grep -rin "error: failed to connect" /var/log --include='*.log'

    Why this is correct

    grep -r searches recursively, -i ignores case, and -n shows line numbers. The --include option limits the search to files matching the glob '*.log', which precisely targets .log files in /var/log and its subdirectories. This satisfies all requirements: case-insensitive, recursive, and line numbers.

About these practice questions

This LFCS question is part of Courseiva's 406-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 →

How Courseiva writes practice questions · Editorial policy

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 Linux Foundation exam blueprint

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.