How to use the tail command in Ubuntu Linux with examples

The ‘tail’ command in Ubuntu Linux enables users to view the end or ‘tail end’ of files, providing output of the last 10 lines by default. This command is versatile, with optional syntax and options modifying its behavior. It can be used to monitor real-time content addition to a file, proving particularly useful for tracking…

This article explains how to use the tail command in Ubuntu.

The tail command in Ubuntu Linux outputs the end or ‘tail end of files. It is a very useful command when working with log files or other constantly updated data. By default, the tail command shows the last 10 lines of a file, but it can be customized to show a different number of lines or bytes.

Additionally, the tail command can be used to monitor real-time content being added to a file, displaying the newest content as it is being added. This makes it a great tool for developers, system administrators, and anyone who needs to monitor important data in real-time on Ubuntu Linux.

About tail command:

The tail command on Ubuntu allows users to output the end or ‘tail end of files. By default, it shows the last 10 lines, like using your mouse and keyboard to read the end of files. The tail is the way to do it on the command line.

 The tail command can also be used to monitor real-time content being added to a file, displaying the newest content as it is being added.

Syntax:

The syntax is the rule and format of how the tail command can be used. The syntax options can be reordered. But a straight format must be followed.,.

Below is an example syntax of how to use the tail command.

tail [OPTION]. FILE.

Options:

The command line options are switches or flags that determine how the commands are executed or controlled. They modify the behavior of the command. They are separated by spaces and followed after the command options.

Below are some options for the tail command:

FILE.Use the -c option to output the last NUM bytes; or use -c +NUM to output starting with byte NUM of each file
-c, –bytes=[+]NUMUse the -c option output the last NUM bytes; or use -c +NUM to output starting with byte NUM of each file
-f, –followUse the -f or –follow option to output appended data as the file grows. this will cause the command to loop forever reading the content as it being added to the file
-n, –lines=[+]NUMUse the -n option output the last NUM lines, instead of the last 10 which is the default
-s num,
–sleep-interval=num
When following with -f or –followsleep for approximately num seconds between file checks. With –pid=pid, check process pidat least once every num seconds.
-v,
–verbose
Verbose output. Print a message for each created directory.
–helpUse the –help option with the command to display this help and exit
–version Use the –version option to output version information and exit

Examples:

Below are some examples of how to run and use the tail on Ubuntu Linux.

Run the command below to output the last 10 lines of the Confidential file without tail command options. This will come just from the last 10 lines of the Confidential file.

tail Confidential

Using the tail command with the -n option will display the -n number of file lines. For example, run the commands below to list the last 100 lines of a file.

tail -n 100 Confidential

When you run the tail command with the -f option, it will display the last 10 lines of the file and loop forever, displaying any new lines being added to the file.

tail -f Confidential

The command above will output the last 10 lines of the Confidential file and monitor it for updates; the tail then continues to output any new lines that are added.

The tail command is a great tool to monitor log files and other data you want to monitor in real time.

When you run tail with the –help option, you’ll see the help text below:

Usage: tail [OPTION]. [FILE].
Print the last 10 lines of each FILE to standard output.
With more than one FILE, precede each with a header giving the file name.

With no FILE, or when FILE is -, read standard input.

That’s it!

I hope you like it, and please come back soon for more Ubuntu Linux commands!

Richard Avatar

Comments

Leave a Reply

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


Exit mobile version