how to continuously display a file of its last several lines of contents
Solution 1:
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>
Solution 2:
This will update every 2 seconds rather than whenever data is written to the file, but perhaps that's adequate:
watch 'head -n 2 job.sta; tail job.sta'
Solution 3:
You can use screen
to simulate the expected behaviour:
Run
screen
, press Space.Press Ctrl+a followed by S to split the screen.
Resize the top window by pressing Ctrl+a followed by
:resize 4
.In the prompt in the top window, enter
head -n2 file
.Move to the bottom window by pressing Ctrl+a followed by Tab.
Start a new screen session by pressing Ctrl+a followed by c.
In the new prompt, enter
tail -f file
.
Solution 4:
I use this script to achieve the effect you describe
!#/bin/bash
while [ 1 ]; do ls -lt data | head -n 30; sleep 3; echo -en "$(tput cuu 30; tput ed)"; done
This runs a command in a loop, and deletes the last lines of the output from the screen before each iteration.
In your case it would look something like
!#/bin/bash
while [ 1 ] ;# loop forever
do
head -n 2 job.sta ;# display first 2 lines
tail -n 30 job.sta ;# display last 30 lines from file
sleep 3 ;# wait a bit
echo -en "$(tput cuu 32; tput ed)" ;# delete last 32 lines from screen
done
Of course it is a bit ugly before your file reaches 30 lines
Hope that helps
Solution 5:
You want the multitail
program, which not only does the split screen stuff but will also do color-coding.
http://www.vanheusden.com/multitail/