How to view the last 10 lines of a file?

QuestionsQuestions8 SkillsProDec, 19 2025
0141

To view the last part of a file, you use the tail command. It is the opposite of the head command.

To view the last 10 lines:

Simply type the command followed by the file path. Like head, tail defaults to 10 lines if you don't specify a number:

tail /tmp/hello

To view a specific number of lines:

If you want to see a specific number of lines (for example, the last 5 lines), use the -n option:

tail -n 5 /tmp/hello

Summary of the "Big Three" for viewing files:

  • cat: Shows the whole file.
  • head: Shows the top of the file.
  • tail: Shows the bottom of the file.

Fun Fact: tail is very popular among developers for watching log files in real-time using the -f (follow) flag: tail -f /var/log/syslog. It keeps the terminal open and prints new lines as they are added to the file

0 Comments

no data
Be the first to share your comment!