LFCS · Question #854
Which of the following commands will print the last 10 lines of a text file to the standard output?
The correct answer is D. tail -n 10 filename. The tail command is used to display the last lines of a file, and the -n option specifies the exact number of lines to output.
Question
Options
- Acat -n 10 filename
- Bdump -n 10 filename
- Chead -n 10 filename
- Dtail -n 10 filename
How the community answered
(58 responses)- A3% (2)
- B5% (3)
- C2% (1)
- D90% (52)
Why each option
The `tail` command is used to display the last lines of a file, and the `-n` option specifies the exact number of lines to output.
The `cat` command concatenates and prints file content, and its `-n` option numbers all output lines, it does not limit the output to the last 10 lines.
The `dump` command is primarily used for filesystem backups, not for displaying specific portions of text files.
The `head` command outputs the *first* part of files, so `head -n 10 filename` would print the first 10 lines, not the last 10.
The `tail` command is specifically designed to output the trailing parts of files, and the `-n 10` option explicitly instructs it to print only the last 10 lines to standard output, fulfilling the requirement.
Concept tested: Linux tail command usage
Source: https://man7.org/linux/man-pages/man1/tail.1.html
Topics
Community Discussion
No community discussion yet for this question.