Similar to the head command which shows you the first few lines of a text file, the tail command lets you to quickly view the last few lines of a text file. It also supports a monitoring mode which displays ongoing changes within the file.
The tail command syntax.
tail [options] file
By default tail will show you the last 10 lines of a text file.
$ tail textfile.txt
You can change the number of lines displayed by adding ‘-n‘ option and adding the number of lines.
$ tail -n 3 textfile.txt
This will show the last 3 lines in the file.
You can keep track of ongoing changes within the file by turning on monitoring mode with the ‘-f‘ option. It is especially helpful when you want to keep an eye on log files.
$ tail -f /var/log/syslog
As lines are appended to the log file they are also displayed by tail.
You can exit the program by pressing Ctrl-C.