When using tail -f
to display the last few lines of a file, how can I make it only ever display 5 lies, overwriting previous lines when the file is added to?
Suppose you want to watch the file "file-to-be-watched", the following may do the trick:
watch -n 1 tail -5 file-to-be-watched
Are you working at a text mode console, or for example via ssh from a desktop environment?
I made a small demo with date
which uses xterm
.
xterm -geometry 60x6 -e bash -c 'while true; do dat=$(date "+%H:%M:%S");echo "Hello $dat";echo "world $dat";echo "alias $dat";echo "blank $dat";echo " $dat"; sleep 1;done'|tail -f
You should be able to replace the while loop with your program, that prints lines every second
tail
outputs continuously. It doesn't clear the the terminal and cannot overwrite already existing lines. I'd say what you're seeking cannot be done, at least not withtail
itself – Sergiy Kolodyazhnyy Jan 5 '17 at 22:55