Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a growing log file for which I want to display only the last 15 lines. Here is what I know I can do:

tail -n 15 -F mylogfile.txt

As the log file is filled, tail appends the last lines to the display.

I am looking for a solution that only displays the last 15 lines and get rid of the lines before the last 15 after it has been updated. Would you have an idea?

share|improve this question
Resize your terminal window to 15 lines. – Jonathan Jan 19 '12 at 19:48
That's a good one too. – mot Jan 20 '12 at 9:08
@Jonathan genius! – Gevorg Sep 19 '15 at 0:00
up vote 64 down vote accepted

It might suffice to use watch:

$ watch tail -n 15 mylogfile.txt
share|improve this answer
Great! Thanks a lot. I also learn the 'watch' command in the process. – mot Jan 19 '12 at 12:41
Wow, watch rocks, thanks! – invert Jan 19 '12 at 21:03

If you use watch, try the -n option to control the interval between each update.

Thus, the following would call tail every 2 seconds

$ watch -n 2 tail -n 15 mylogfile.txt

while this one polls it every 1 second

$ watch -n 1 tail -n 15 mylogfile.txt
share|improve this answer

You could stream the logfile running less and pressing SHIFT + F that will stream the file using less. $ less mylogfile.txt Then just press SHIFT + F and it will stream. I think it is convenient for monitoring log files that update.

share|improve this answer
That's a very nice one! – kaiser Mar 10 at 15:21

Maybe you find the -d param handy.

man watch

-d Highlight the differences between successive updates. Option will read optional argument that changes highlight to be permanent, allowing to see what has changed at least once since first iteration.

share|improve this answer
Good catch too! – mot May 28 '13 at 19:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.