Have you ever needed to look at the last entries in a log file.
Of course you have.
For example you want to see the last errors in the /var/logs/mail.log file
If you open it with NANO or some other txt editing programme you will have to scroll all the way to the bottom.
AND if more entries are logged while you are already in the file you will not see them!
This is a pain
“Tail” is very useful because in its simplest form
It will show you the last 10 lines of txt form the log file
If you add the -f command it will follow the file. Meaning if any lines are added to the log file they will appear real time
tail -f /var/logs/mail.log
Use the “-F” option to force tail to follow file names rather than file objects. This can prevent problems with log rotation and other programs that may alter file names.
Filter Lines in Followed Logs with grep
The grep tool can be combined with tail to filter the contents of a log file in real time. Consider the following examples:
tail -F procmail.log | grep -e “^Subject”
tail -F access.log | grep “404″
In the first command, only the lines of the procmail.log file that begin with the characters “Subject” are printed. All other lines are discarded.
In the second invocation, only entries from the access log that contain the characters “404″ will be printed. All other lines are discarded.
output the last N lines, instead of the last 10
–retry, keep trying to open a file even if it is inaccessible when tail starts or if it becomes inaccessible later – useful only with -f