How to display the last few lines?

To display the last few lines of a file in Linux, you can use the tail command. Here’s how to do it:

Basic Usage

To display the last 10 lines of a file (which is the default), you can use:

tail filename.txt

Specifying the Number of Lines

If you want to display a specific number of lines, you can use the -n option. For example, to display the last 5 lines:

tail -n 5 filename.txt

Displaying the Last Lines of Multiple Files

You can also display the last few lines of multiple files at once:

tail -n 5 file1.txt file2.txt

Continuous Monitoring

If you want to continuously monitor a file for new lines (like a log file), you can use the -f option:

tail -f filename.txt

This command will display the last 10 lines and then keep the terminal open, showing new lines as they are added to the file.

Summary

  • Use tail filename.txt for the last 10 lines.
  • Use tail -n N filename.txt to specify the number of lines.
  • Use tail -f filename.txt for real-time monitoring of a file.

0 Comments

no data
Be the first to share your comment!