Articles
linux
What is TAIL in Linux and how you should use it!linux

You might wonder 'how do I get the last lines of a log file' or 'how do I get new lines written to a file in linux'. Well tail is what you need!

What is tail?

Tail is a program which Outputs a number of lines from a file depending on what arguments you call it with. There are quite a few arguments you can add but the core what is useful is below.

Usage

You can invoke tail but where it really shines is in a pipe operation.

Last 5 lines

./someFile.txt | tail -n 5

To print any new lines

./someFile.txt | tail -f

Useful Arguments to Remember

ARG Name Action
-f follow output new lines on the end
-F follow and retry follow and retry if the file is inaccessible
-n # number number of lines to output when the command is run
+ # number of lines to output at the start of the file
- # number of lines to output at the end of the file