LX0-103 · Question #41
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 displays the end of a file, and the -n flag specifies the number of lines to show from the bottom.
Question
Which of the following commands will print the last 10 lines of a text file to the standard output?
Options
- Acat -n 10 filename
- Bdump -n 10 filename
- Chead -n 10 filename
- Dtail -n 10 filename
How the community answered
(19 responses)- A5% (1)
- B5% (1)
- C5% (1)
- D84% (16)
Why each option
The tail command displays the end of a file, and the -n flag specifies the number of lines to show from the bottom.
cat -n numbers all lines and outputs the entire file, it does not accept a numeric argument to limit output to a specific number of lines.
dump is a filesystem backup utility and does not accept -n 10 filename syntax for printing file content.
head -n 10 filename prints the first 10 lines of a file, not the last 10.
The tail command is specifically designed to output the last lines of a file. Using tail -n 10 filename instructs the shell to read the file and print only the final 10 lines to standard output, which is exactly the behavior described in the question.
Concept tested: Using tail command to view end of file
Source: https://man7.org/linux/man-pages/man1/tail.1.html
Topics
Community Discussion
No community discussion yet for this question.