nerdexam
Linux_Foundation

LFCS · Question #834

Which command will print line numbers before each line in a file?

The correct answer is C. cat-n. The cat -n command is used to concatenate and display file contents to standard output, with each line preceded by its corresponding line number.

Submitted by weili_xi· Apr 18, 2026Essential Commands

Question

Which command will print line numbers before each line in a file?

Options

  • AIn
  • Bnl
  • Ccat-n
  • Dnumline

How the community answered

(28 responses)
  • A
    7% (2)
  • B
    4% (1)
  • C
    89% (25)

Why each option

The `cat -n` command is used to concatenate and display file contents to standard output, with each line preceded by its corresponding line number.

AIn

The `ln` command is used for creating links (hard or symbolic) between files, not for numbering lines.

Bnl

The `nl` command is also used to number lines, but the option provided, `nl`, is just the command name without the file argument, and `cat -n` is a more direct and commonly recognized option among the choices.

Ccat-nCorrect

The `cat` command with the `-n` option (`cat -n file`) displays the contents of a file to standard output, adding a line number to each line of the output. This is a common and straightforward method for numbering lines.

Dnumline

`numline` is not a standard Linux command for numbering lines in a file.

Concept tested: Linux file viewing with line numbers

Source: https://man7.org/linux/man-pages/man1/cat.1.html

Topics

#cat command#line numbering#file viewing#command options

Community Discussion

No community discussion yet for this question.

Full LFCS Practice