Linux Tail Command | Linuxize

The tail command shows the final half (10 traces by default) of a number of recordsdata or piped information. It may be additionally used to watch the file modifications in actual time.

One of the vital widespread makes use of of the tail command is to look at and analyze logs and different recordsdata that change over time, normally mixed with different instruments like grep.

On this tutorial, we are going to present you learn how to use the Linux tail command by way of sensible examples and detailed explanations of the most typical tail choices.

Tail Command Syntax

Earlier than going into learn how to use the tail command, let’s begin by reviewing the fundamental syntax.

The tail command expressions take the next kind:

tail [OPTION]… [FILE]…

  • OPTION – tail choices. We’ll go over the most typical choices within the subsequent sections.
  • FILE – Zero or extra enter file names. If no FILE is specified, or when FILE is -, tail will learn the usual enter.

Learn how to Use the Tail Command

In its easiest kind when used with none possibility, the tail command will show the final 10 traces.

Learn how to Show a Particular Variety of Strains

Use the -n (–lines) choice to specify the variety of traces to be proven:

tail -n <NUMBER> filename.txt

You may as well omit the letter n and use simply the hyphen (-) and the quantity (with no house between them).

To show the final 50 traces of a file named filename.txt you’ll use:

The next instance will show the identical end result because the above instructions:

Learn how to Show a Particular Variety of Bytes

To indicate a selected variety of bytes use the -c (–bytes) possibility.

tail -c <NUMBER> filename.txt

For instance to show the final 500 bytes of information from the file named filename.txt you’ll use:

You may as well use a multiplier suffix after the quantity to specify the variety of bytes to be proven. b multiplies it by 512, kB multiplies it by 1000, Okay multiplies it by 1024, MB multiplies it by 1000000, M multiplies it by 1048576, and so forth.

The next command will show the final two kilobytes (2048) of the file filename.txt:

Learn how to Watch a File for Modifications

To watch a file for modifications use the -f (–follow) possibility:

This feature is especially helpful for monitoring log recordsdata. For instance, to show the final 10 traces of the /var/log/nginx/error.log file, and monitor the file for updates you’ll use:

tail -f /var/log/nginx/error.log

To interrupt the tail command whereas it’s watching a file, press Ctrl+C.

To maintain monitoring the file when it’s recreated, use the -F possibility.

This feature is beneficial in conditions when the tail command is following a log file that rotates. When used with -F possibility the tail command will reopen the file the as quickly because it grew to become obtainable once more.

Learn how to Show A number of Information

If a number of recordsdata are supplied as enter to the tail command, it is going to show the final ten traces from every file.

tail filename1.txt filename2.txt

You need to use the identical choices as when displaying a single file.

This instance exhibits the final 20 traces of the recordsdata filename1.txt and filename2.txt:

tail -n 20 filename1.txt filename2.txt

Learn how to Use Tail with Different Instructions

The tail command can be utilized together with different instructions by redirecting the usual output from/to different utilities utilizing pipes.

For instance to watch the apache entry log file and solely show these traces that comprise the IP tackle you’ll use:

tail -f /var/log/apache2/entry.log | grep

The next command will show the highest ten operating processes sorted by CPU utilization:

ps aux | type -nk +3 | tail -5


By now it’s best to have a great understanding of learn how to use the Linux tail command. It’s complementary to the head command which prints the primary traces of a file to the to the terminal.


Germany Devoted Server

Leave a Reply