CentOS Debian Mint openSUSE Red Hat Ubuntu

tail Command in Linux

tail Command in Linux

Introduction

tail command is the supplement of the head command. This command tells you the last data of the file input. Normally by default, the tail command prints out the last 10 lines of the file.

tail command is the best and useful way to see the most recently added data. It can also monitor a file and show each new data added to that file as they happen.

Below is the section that guides you on how to use the tail command in Linux as you go through below.

The syntax of tail command

$ tail [option]... [file]...

Here I have a file named animal.txt. Let’s see what’s inside:

$ cat animal.txt

Output:

Options

1. Without any option it will print out the last 10 lines

$ tail animal.txt

Output:

2. -n num: Specifies the number of last lines to be printed

For example, I will print out the last 3 lines:

$ tail -n 3 animal.txt

Output:

Another way:

$ tail -3 animal.txt

Output:

With + option, it will print out from the specified line to the last line

For example, I will print out from the 4th line to the last line:

$ tail +4 animal.txt

Output:

3. -c num: Prints out the last characters of the specified file. Each character is treated as 1 byte. With -num, it will print out the last num characters of the file. With +num, it will skip the first num characters and start printing out from the num character.

For example, I will print out the last 3 characters:

$ tail -c -4 animal.txt

Output:

For example, I want to print out from the 4th byte:

$ tail -c +4 animal.txt

Output:

4. -q: To execute multiple files at once

I will use the tail command with 2 files animal.txt and vege.txt:

$ tail animal.txt vege.txt

Output:

5. -v: Filenames always show the beginning

$ tail -v animal.txt

Output:

6. –version: Check your version

$ tail --version

Output:

Conclusion

We just showed you how to use the tail command in Linux.

Thanks for reading!

Similar Posts