tailf Command in Linux

This tutorial explains Linux “tailf” command, options and its usage with examples.

tailf – follow the growth of a log file

DESCRIPTION

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.

SYNOPSIS

tailf [OPTION] file

advertisement

OPTION :

-n, –lines=N, -N
output the last N lines, instead of the last 10.

EXAMPLES

Free 30-Day Java Certification Bootcamp is Live. Join Now!

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 24.10.160.10

In this above example, we’re watching the access.log for any IP address of 24.10.160.10

advertisement

Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.

If you wish to look at all Linux commands and their usage examples, go to Linux Commands Tutorial.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
I’m Manish - Founder and CTO at Sanfoundry. I’ve been working in tech for over 25 years, with deep focus on Linux kernel, SAN technologies, Advanced C, Full Stack and Scalable website designs.

You can connect with me on LinkedIn, watch my Youtube Masterclasses, or join my Telegram tech discussions.

If you’re in your 40s–60s and exploring new directions in your career, I also offer mentoring. Learn more here.