Display last lines of a text file
The tail command is used to display (by default) the last 10 lines of a text file. It is useful when examining log files, since it can show you the most recent log events.
The /var/log/messages is probably the most important log file in Raspbian. It records a variety of events, such as system error messages, system startups and shutdowns, network configuration changes, etc. This is probably the first place to look for error messages if your system is experiencing problems. To display the most recent events logged in this file, we can use the tail command:
As you can see in the picture above, the tail command displayed only the last 10 lines of the /var/log/messages file. If you want to display more that the last 10 lines, use the -n option to specify the number of lines to be displayed:
In the picture above you can see that we’ve displayed the last 13 lines of the /var/log/messages file.
Another useful option that can be used with the tail command is the -f option. When used with this option, the tail command keeps the file open and displalys new lines as they are being added to the file: