Courseiva
GNU and Unix CommandseasyMultiple SelectObjective-mapped

LPIC-1 GNU and Unix Commands Practice Question

Which TWO of the following commands output the total number of lines in a file?

⚠ Common exam trap

Candidates often think `grep -c '.'` counts all lines, but it actually excludes empty lines, while `nl` outputs numbered lines rather than a single total count.

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

sed -n '$='

The `sed -n '$='` command prints the line number of the last line of the file, which is equivalent to the total number of lines. The `wc -l` command counts the number of newline characters, which directly gives the total line count. Both commands output the total number of lines in a file.

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 -c '.'

    Why it's wrong here

    grep -c '.' counts lines that contain at least one character (non-empty lines).

  • nl

    Why it's wrong here

    nl numbers all lines but does not output a total count.

  • head -n 1

    Why it's wrong here

    head -n 1 prints the first line, not the total count.

  • sed -n '$='

    Why this is correct

    sed -n '$=' prints the line number of the last line, equivalent to the total line count.

  • wc -l

    Why this is correct

    wc -l counts lines (newline characters).

About these practice questions

One of 527 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 →

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.