nerdexam
LPI

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.

The Power of the Command Line

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)
  • A
    3% (1)
  • B
    17% (6)
  • C
    8% (3)
  • D
    72% (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.

Ahead -n 1 foo.txt

'head -n 1 foo.txt' displays the first line of the file, not the last, because 'head' reads from the beginning of the file.

Btail foo.txt

'tail foo.txt' without the '-n' option defaults to displaying the last 10 lines of the file, not just the single last line.

Clast -n 1 foo.txt

'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'.

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, 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

#tail command#file viewing#text processing

Community Discussion

No community discussion yet for this question.

Full 010-100 Practice