Generally you wish to monitor what new data is being written to a file (consider log recordsdata), or for no matter causes, wish to entry the previous few traces of a file. Nicely, there is a command line utility that allows you to do that in Linux, and it is name tail.

On this tutorial, we are going to talk about the fundamentals of the tail command utilizing some straightforward to know examples. However earlier than we do this, it is value mentioning that each one examples included on this article have been examined on Ubuntu 16.04 LTS.

Linux tail command

As already talked about, the tail command outputs the final a part of recordsdata provided to it as enter. Following is its syntax:

tail [OPTION]… [FILE]…

And this is what the device’s man web page says about it:

Print the final 10 traces of every FILE to plain output. With multiple FILE, precede every with
a header giving the file identify. With no FILE, or when FILE is -, learn commonplace enter.

Following are some Q&A-styled examples that ought to offer you a greater thought on how the tail command works.

Q1. The best way to use tail?

Primary utilization could be very straightforward – all it’s a must to do is to go the identify of the file whose final 10 traces you need the device to show. For instance:

tail file1

Following had been the final 10 traces in file2 on my system:

How to use tail command

Q2. The best way to change variety of traces tail prints?

As by now, the tail command prints 10 traces by default. Nonetheless, you may change this quantity utilizing the -n command line possibility.

tail -n [num] [filename]

For instance:

tail -n 5 file2

How to change number of lines tail prints

Q3. The best way to make tail output a set variety of bytes?

What if as a substitute of traces, you need tail to deal in bytes. I imply, what if the requirement is to print 20 bytes? Nicely, this may be completed utilizing the -c command line possibility.

tail -c [num] [filename]

For instance:

tail -c 20 file2

How to make tail output a set number of bytes

This fall. The best way to make tail comply with log recordsdata?

If you wish to use tail to comply with updates to a file (say a log file) in real-time, use the -F or –follow command line possibility.

tail -F [filename]

For instance:

tail -F file2

Be aware that -f is the same as ‘–follow=identify –retry’.

Here is some data the person web page lists in regards to the -f/-F/–follow choices:

With --follow (-f), tail defaults to following the file descriptor, which signifies that even when a 
tail'ed file is  renamed,  tail  will proceed  to  monitor  its finish.  This default conduct will not be
fascinating once you actually wish to monitor the precise identify of the file, not the file descriptor
(e.g., log rotation).  Use --follow=identify in that case. That causes tail to trace the named file in
a means that accommodates renaming, removing and creation.

Q5. The best way to power tail to maintain attempting accessing enter file?

Generally a file could also be quickly inaccessible, one thing which might occur attributable to a wide range of causes. To verify tail retains attempting opening the file, use the –retry possibility.

tail –retry [filename]


In order that’s how the tail command works. Hope you’d have loved the tutorial, in addition to discovered helpful stuff from it. We propose you check out these examples in your Linux PC, after which head to the device’s man web page for more information.

What’s Hyper Threading Expertise as Quick As Doable

Previous article

10 Free Infographic Templates for Your Design Tasks

Next article

You may also like


Leave a reply

Your email address will not be published. Required fields are marked *

More in Linux