How to see the whole file and also wait for more data to be added to that file

command linetail

I want to read whole file and make it waiting for input, just like tail -f but with the complete file displayed.

The length of this file will always change, because this is a .log file.

How can I do it, if I don't know length of the file?

Best Answer

tail lets you add -n to specify the number of lines to display from the end, which can be used in conjunction with -f. If the argument for -n starts with + that is the count of lines from the beginning (0 and 1 displaying the whole file, 2 indicating skip the first line, as indicated by @Ben). So just do:

tail -f -n +0 filename

If your log files get rotated, you can add --retry (or combine -f and --retry into -F as @Hagen suggested)

Also note that in a graphical terminal, you can use the mouse and PageUp/PageDown to scroll back into the history (assuming your buffer is large enough), this information stays there even if you use Ctrl+C to exit tail. If you use less this is far less convenient and AFAIK you have to use the keyboard for scrolling and I don't know of a means to keep less from deinitialising termcap if you forget to start it with -X.

Related Question