Ubuntu – tail: Reading an entire file, and then following

tail

I would like a tail -f type of behavior that reads the entire file and then continues to follow it as it's written to.


SOLUTION

Based on the answer I accepted, this works: tail -f -n +1 {filename}

Why it works: The -f option continues to "follow" the file and output new lines as they are written to the file. The -n +1 instructs tail to start reading the file from the first line. Using -n -10 would start with the last ten lines of the file.

Best Answer

Use

tail -f -n +1

Using man tail will give you more details, the relevant excerpt follows.

<snip>Numbers having a leading plus (`+') sign are relative to the
beginning of the input, for example, ``-n +2'' starts the display at the
second line of the input.</snip>

-f      The -f option causes tail to not stop when end of file is
        reached, but rather to wait for additional data to be appended to
        the input.  The -f option is ignored if the standard input is a
        pipe, but not if it is a FIFO.

-n number
        The location is number lines.