010-150 · Question #17
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 by limiting output to one line from the end.
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
(22 responses)- B9% (2)
- C14% (3)
- D77% (17)
Why each option
The `tail -n 1` command displays exactly the last line of a file by limiting output to one line from the end.
`head -n 1` displays the first line of the file, not the last line.
`tail` without the `-n` flag defaults to displaying the last 10 lines, not just the last single line.
`last` is a system utility that displays a history of user logins and reboots; it does not read file content.
The `tail` command reads from the end of a file, and the `-n 1` option restricts output to exactly one line. Together, `tail -n 1 foo.txt` prints only the final line of the file.
Concept tested: Linux tail command single last line retrieval
Source: https://man7.org/linux/man-pages/man1/tail.1.html
Topics
Community Discussion
No community discussion yet for this question.