How can I see the whole file and also wait for more data to be added to that file?
There is a way better way of achieving this:
less +F <file>
It'll show you the whole file, has the full power of less
and will wait for new input. If you want to stop waiting for input, and read a specific part, you can stop it with ^C
and resume with F
.
The F
command is always available in less
, if you decide to watch for changes while having a file open in less
, hitting F
will turn it on. Thanks to hiergiltdiestfu and wildcard for pointing that out.
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
.
watch
command should do that for you.
You can also try
less +FG
You will have more options with less
command to scroll through your file as you say it's a large file.