nerdexam
LPI

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.

Exercise Leadership and Client Education

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)
  • B
    9% (2)
  • C
    14% (3)
  • D
    77% (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.

Ahead -n 1 foo.txt

`head -n 1` displays the first line of the file, not the last line.

Btail foo.txt

`tail` without the `-n` flag defaults to displaying the last 10 lines, not just the last single line.

Clast -n 1 foo.txt

`last` is a system utility that displays a history of user logins and reboots; it does not read file content.

Dtail -n 1 foo.txtCorrect

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

#tail command#last line display#file viewing#Linux CLI

Community Discussion

No community discussion yet for this question.

Full 010-150 Practice