I have a script that collects the size of a file that is being constantly fed. I'm echoing its size to a log file (echo 'filesize is $size' > log.txt) so I only have the last size information. So, only one line.
Now, in another terminal, I wanted to tail that log file to see its size increasing in real time. It turns out, tail -f path/to/file gives me the output I want but it keeps jumping to the next line (as expected, I guess).
So, the output is something like:
$ tail -F log.txt 2>/dev/null
filesize is 1.658 GB
filesize is 1.659 GB
filesize is 1.659 GB
filesize is 1.660 GB
I wanted something more like the command "less" in which you don't have the cursor back. Maybe a better example would be "mtr", that keeps updating the information on the screen without going to next line (as opposed to traceroute).
Thank you,
Use this command.
watch tail -n 1 log.txt
while [ 1 ]; do sleep 1; clear; tail log.txt; done
This does not have the drawback of passing command and arguments to watch
(sometimes you need to hop extra loops to make it correctly), and it clears the terminal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With