Sometimes I am running a less +F
on a log file, which I then truncate. I would like less
to realize that the file has been truncated and start following the file as it is now. Currently, I am forced to do the following:
- (terminal 1) >
less +F my-file.txt
- (terminal 2) >
printf "" > my-file.txt
- (terminal 1) > quit less
- (terminal 1) > restart less:
less +F my-file.txt
And I have to do steps 3-4 every time that I truncate the file (which is dozens o times a day). This is really a pain.
I would like to do:
- (terminal 1) >
less +F my-file.txt
(and whatever extra option is needed) - (terminal 2) >
printf "" > my-file.txt
And that's it. less
would be automatically aware that the file has been truncated, and start following the new file from the beginning.
Is this possible? What flag should I use for less to achieve this?