nerdexam
LPI

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.

Exercise Leadership and Client Education

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)
  • A
    4% (2)
  • B
    14% (7)
  • C
    8% (4)
  • D
    74% (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.

AThe first 20 lines of test.txt.

Displaying the first lines is the behavior of the `head` command, not `tail`.

BThe last 20 lines of test.txt omitting the blank lines.

`tail` does not filter or omit blank lines; it outputs all lines including blank ones exactly as stored in the file.

CThe last 20 lines of test.txt with line numbers.

`tail` does not prepend line numbers; that functionality requires a separate command such as `nl` or `cat -n`.

DThe last 20 lines of test.txt including blank lines.Correct

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

#tail command#file viewing#line output#Linux CLI

Community Discussion

No community discussion yet for this question.

Full 010-150 Practice