how to continuously display a file of its last several lines of contents

Wen_CSE picture Wen_CSE · Jan 30, 2013 · Viewed 37.3k times · Source

I am trying to find a Unix command (combination, maybe) on how to continuously display a file of its last several lines of contents. But during this displaying, I want some of the top lines are always displayed on the screen top when the rolling contents reach the screen top.

Is that possible?

(1) Suppose I have file, "job.sta", the first 2 lines are: job name, John's job on 2013-Jan-30,... Tab1, Tab2, Tab3 0, 1, 2, 1, 90, 89 2, 89, 23 ...

(2) This file is on its running, its contents are growing, and I don't know what line it's going to end.

(3) So I want to display (always) the first 2 lines when using tail command, when the updating contents reaches a Unix shell screen top. I am using PuTTY at the moment.

Reference: http://www.unix.com/unix-dummies-questions-answers/172000-head-tail-how-display-middle-lines.html

Answer

wacko413 picture wacko413 · Mar 27, 2014

I use this function all the time to monitor a log file in another terminal window.

tail -f <filename>

I recommend taking it a step forward to look for particular text in the log. Great if you are only interested in seeing some particular entry being written to the file.

tail -f <filename> | grep <keyword or pattern>