How to display last lines of a file?

0237

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

Basic Usage

To display the last 10 lines of a file, use:

tail filename.txt

Customizing the Number of Lines

If you want to display a specific number of lines from the end of the file, you can use the -n option followed by the number of lines you want to see. For example, to display the last 5 lines:

tail -n 5 filename.txt

Example

Assuming you have a file named example.txt, you can run:

tail example.txt

This will show the last 10 lines. If you want to see the last 3 lines, you would run:

tail -n 3 example.txt

Continuous Monitoring

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

tail -f filename.txt

This will keep the terminal open and display new lines as they are added to the file.

If you have any further questions or need more examples, feel free to ask!

0 Comments

no data
Be the first to share your comment!