Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using tail -F to see a file changing in real-time

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,

like image 934
Adriano_Pinaffo Avatar asked Jan 20 '17 05:01

Adriano_Pinaffo


2 Answers

Use this command.

watch tail -n 1 log.txt
like image 157
OregonTrail Avatar answered Sep 21 '22 07:09

OregonTrail


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.

like image 31
Jakub M. Avatar answered Sep 21 '22 07:09

Jakub M.