Courseiva
GNU and Unix Commands →easyMultiple Select

LPIC-1 GNU and Unix Commands Practice Question

Which THREE of the following are correct features of the 'grep' command? (Choose three.)

⚠ Common exam trap

A common mix-up: candidates confuse `-l` (list filenames) with `-n` (show line numbers) and assume `-r` enables regex, when in fact `-r` is for recursive directory traversal and regex is the default behavior.

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 makes the search case-insensitive

Option A is correct because grep -i performs a case-insensitive search, so patterns like 'error' will also match 'Error' or 'ERROR'. Option B is correct because grep -v inverts the match, printing only the lines that do NOT contain the specified pattern. Option C is correct because grep -c suppresses normal output and instead prints a count of the matching lines. Option D is not correct because -l lists only the names of files containing matches, while line numbers are shown with -n. Option E is not correct because -r enables recursive searching through directories; regular expression matching is grep's default behavior, not enabled by -r.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✓

    -i makes the search case-insensitive

    Why this is correct

    The `-i` flag instructs `grep` to ignore case distinctions in both the pattern and the input, so "Error", "error" and "ERROR" all match. This directly satisfies the stem's requirement for a genuine `grep` feature, as case-insensitive matching is a documented, standard option across GNU and BSD implementations.

  • ✓

    -v inverts the match

    Why this is correct

    The `-v` flag inverts the match, printing only lines that do not contain the specified pattern. This satisfies the question's requirement for a genuine grep feature, as inversion is a core matching modifier rather than an output-formatting or recursion option.

  • ✓

    -c counts matching lines

    Why this is correct

    The `-c` flag suppresses normal matched-line output and instead prints only a count of lines containing matches, satisfying the stem's requirement for a genuine grep feature. This differs from `-n`, which prefixes line numbers, and `-l`, which lists filenames only. Counting is per line, not per occurrence.

  • ✗

    -l prints line numbers of matches

    Why it's wrong here

    The -l flag lists only the names of files containing matches; line numbers come from -n. It is tempting because grep does have a flag for line numbers, and -l is easily confused with it, but -l would be the right choice when you need filenames alone for scripting.

  • ✗

    -r enables regular expression matching

    Why it's wrong here

    The -r flag performs recursive searches through directories; regular expression matching is grep's default behaviour, not enabled by -r. It is tempting because recursive searching is a genuine grep feature, and -r would be correct when you need to search every file beneath a directory tree.

About these practice questions

This LPIC-1 question is part of Courseiva's 402-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 by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

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.