nerdexam
CompTIA

LX0-103 · Question #21

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

The correct answer is C. cat-n. The cat -n command (shown as 'cat-n' here) prints file contents with sequential line numbers prepended to every line. The nl command also numbers lines but with different default behavior.

GNU and Unix Commands

Question

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

Options

  • AIn
  • Bnl
  • Ccat-n
  • Dnumline

How the community answered

(45 responses)
  • A
    9% (4)
  • B
    2% (1)
  • C
    87% (39)
  • D
    2% (1)

Why each option

The cat -n command (shown as 'cat-n' here) prints file contents with sequential line numbers prepended to every line. The nl command also numbers lines but with different default behavior.

AIn

The ln command creates hard or symbolic links between files and has no functionality related to printing line numbers.

Bnl

While nl is a real line-numbering command, it skips blank lines by default and is not the answer designated correct here; cat -n numbers every line unconditionally.

Ccat-nCorrect

The cat -n flag instructs cat to number all output lines sequentially, including blank lines, printing the line number before each line of the file. It is the standard and most direct way to display line-numbered file output in Linux and Unix systems.

Dnumline

numline is not a valid Linux or Unix command.

Concept tested: Linux cat -n option for line-numbered output

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

Topics

#nl command#cat -n#line numbers#text display

Community Discussion

No community discussion yet for this question.

Full LX0-103 Practice