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.txtfor the last 10 lines. - Use
tail -n N filename.txtto specify the number of lines. - Use
tail -f filename.txtfor real-time monitoring of a file.
