nerdexam
CompTIA

LX0-103 · Question #41

Which of the following commands will print the last 10 lines of a text file to the standard output?

The correct answer is D. tail -n 10 filename. The tail command displays the end of a file, and the -n flag specifies the number of lines to show from the bottom.

GNU and Unix Commands

Question

Which of the following commands will print the last 10 lines of a text file to the standard output?

Options

  • Acat -n 10 filename
  • Bdump -n 10 filename
  • Chead -n 10 filename
  • Dtail -n 10 filename

How the community answered

(19 responses)
  • A
    5% (1)
  • B
    5% (1)
  • C
    5% (1)
  • D
    84% (16)

Why each option

The tail command displays the end of a file, and the -n flag specifies the number of lines to show from the bottom.

Acat -n 10 filename

cat -n numbers all lines and outputs the entire file, it does not accept a numeric argument to limit output to a specific number of lines.

Bdump -n 10 filename

dump is a filesystem backup utility and does not accept -n 10 filename syntax for printing file content.

Chead -n 10 filename

head -n 10 filename prints the first 10 lines of a file, not the last 10.

Dtail -n 10 filenameCorrect

The tail command is specifically designed to output the last lines of a file. Using tail -n 10 filename instructs the shell to read the file and print only the final 10 lines to standard output, which is exactly the behavior described in the question.

Concept tested: Using tail command to view end of file

Source: https://man7.org/linux/man-pages/man1/tail.1.html

Topics

#tail#text processing#standard output#file viewing

Community Discussion

No community discussion yet for this question.

Full LX0-103 Practice