Tell me more ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

Thank you!

share|improve this question
5  
Resize your terminal window to 15 lines. – Jonathan Jan 19 '12 at 19:48
That's a good one too. – Marc-Olivier Titeux Jan 20 '12 at 9:08

3 Answers

up vote 21 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. – Marc-Olivier Titeux 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

Your Answer

 
discard

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.