This tutorial explains Linux “tailf” command, options and its usage with examples.
tailf will print out the last 10 lines of a file and then wait for the file to grow. It is similar to tail -f but does not access the file when it is not growing. This has the side effect of not updating the access time for the file, so a filesystem flush does not occur periodically when no log activity is happening. tailf is extremely useful for monitoring log files on a laptop when logging is infrequent and the user desires that the hard disk spin down to conserve battery life.
tailf [OPTION] file
-n, –lines=N, -N
output the last N lines, instead of the last 10.
1. Display the last 5 lines and then update the file as new lines are being added
$ tailf -n 5 myfile.txt
This is a great command to use to watch log files or logs in real-time.
2. If you’re trying to view a file such as the Apache access log file that is updated frequently you can pipe its output through the grep command to filter out only the content you want.
$ tailf access.log | grep 188.8.131.52
In this above example, we’re watching the access.log for any IP address of 184.108.40.206
Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.