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.
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)- A9% (4)
- B2% (1)
- C87% (39)
- D2% (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.
The ln command creates hard or symbolic links between files and has no functionality related to printing line numbers.
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.
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.
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
Community Discussion
No community discussion yet for this question.