I'm using tail -f
to print the content of a continuously changing file. When the file is truncated it shows up like this:
blah (old)..
blah more (old)..
tail: file.out: file truncated
blah..
blah more..
This can get messy when I change the file too often so that it becomes hard to see where the file begins/ends. Is there a way to somehow clear
the screen when the file is truncated so that it would show up like this?
tail: file.out: file truncated
blah..
blah more..
No, tail doesn't read the whole file, it seeks to the end then read blocks backwards until the expected number of lines have been reached, then it displays the lines in the proper direction until the end of the file, and possibly stays monitoring the file if the -f option is used.
You can stop the output by pressing Ctrl + C (like it's the case with most programs inside the linux shell).
In linux shell when you type a "\" after a command it translates it to a "more code to come on the next line" Thus when you typed "ls \" the shell expects you to add more code or add a newline char. - Hit CTRL + C, which will terminate the command without any output.
I know this is old, but another (potentially simpler) solution is:
watch -n 1 cat myfile.txt
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