Print Last 10 Lines of a Text File in Linux | LFCS Exam Preparation

Print Last 10 Lines of a Text File

Question

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

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

D

The correct answer is D. tail -n 10 filename

Explanation:

The tail command is used to display the last part of a file. By default, it displays the last 10 lines of the file, but this can be changed with the -n option.

The option -n 10 specifies that we want to display the last 10 lines of the file.

The cat command (option A) displays the entire file, with or without line numbers depending on the option used. So, cat -n 10 filename would display the entire file with line numbers, starting from line 10.

The dump command (option B) is used for backing up file systems, and it is not used for displaying the contents of a file.

The head command (option C) is used to display the first part of a file, not the last. The -n option can be used to specify the number of lines to display.

Therefore, option D, tail -n 10 filename, is the correct answer to display the last 10 lines of a text file to the standard output.