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.
Question
Options
- AIn
- Bnl
- Ccat-n
- Dnumline
How the community answered
(28 responses)- A7% (2)
- B4% (1)
- C89% (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.
The `ln` command is used for creating links (hard or symbolic) between files, not for numbering lines.
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.
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.
`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
Community Discussion
No community discussion yet for this question.