010-100 · Question #79
Which command will display the last line of the file foo.txt?
The correct answer is D. tail -n 1 foo.txt. The 'tail -n 1' command displays exactly the last line of a file. Other options either show the first line, show multiple lines by default, or are not valid commands.
Question
Which command will display the last line of the file foo.txt?
Options
- Ahead -n 1 foo.txt
- Btail foo.txt
- Clast -n 1 foo.txt
- Dtail -n 1 foo.txt
How the community answered
(36 responses)- A3% (1)
- B17% (6)
- C8% (3)
- D72% (26)
Why each option
The 'tail -n 1' command displays exactly the last line of a file. Other options either show the first line, show multiple lines by default, or are not valid commands.
'head -n 1 foo.txt' displays the first line of the file, not the last, because 'head' reads from the beginning of the file.
'tail foo.txt' without the '-n' option defaults to displaying the last 10 lines of the file, not just the single last line.
'last' is a command that displays login history from the system's wtmp file and is not used for reading file contents - it is not a valid substitute for 'tail'.
The 'tail' command reads from the end of a file, and the '-n 1' option restricts output to exactly one line, so 'tail -n 1 foo.txt' outputs only the final line of foo.txt.
Concept tested: Linux tail command to display specific file lines
Source: https://man7.org/linux/man-pages/man1/tail.1.html
Topics
Community Discussion
No community discussion yet for this question.