Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clear screen when the file is truncated while using `tail -f`

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..
like image 323
none Avatar asked Oct 08 '12 16:10

none


People also ask

Does tail read whole file?

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.

How do I get out of LS?

You can stop the output by pressing Ctrl + C (like it's the case with most programs inside the linux shell).

How Stop ls command?

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.


1 Answers

I know this is old, but another (potentially simpler) solution is:

watch -n 1 cat myfile.txt

like image 184
Rhys Avatar answered Sep 30 '22 19:09

Rhys