010-150 · Question #15
What is the output of the following command? tail -n 20 test.txt
The correct answer is D. The last 20 lines of test.txt including blank lines. The tail -n 20 command outputs the last 20 lines of a file exactly as they appear, including any blank lines.
Question
What is the output of the following command? tail -n 20 test.txt
Options
- AThe first 20 lines of test.txt.
- BThe last 20 lines of test.txt omitting the blank lines.
- CThe last 20 lines of test.txt with line numbers.
- DThe last 20 lines of test.txt including blank lines.
How the community answered
(50 responses)- A4% (2)
- B14% (7)
- C8% (4)
- D74% (37)
Why each option
The `tail -n 20` command outputs the last 20 lines of a file exactly as they appear, including any blank lines.
Displaying the first lines is the behavior of the `head` command, not `tail`.
`tail` does not filter or omit blank lines; it outputs all lines including blank ones exactly as stored in the file.
`tail` does not prepend line numbers; that functionality requires a separate command such as `nl` or `cat -n`.
The `tail` command with `-n 20` prints the final 20 lines of the specified file. It performs no filtering or formatting, so blank lines are included in the output just as they exist in the file.
Concept tested: Linux tail command output behavior with -n flag
Source: https://man7.org/linux/man-pages/man1/tail.1.html
Topics
Community Discussion
No community discussion yet for this question.