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
1. Without any option it will print out the last 10 lines
$ tail animal.txt
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
$ tail -3 animal.txt
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
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
For example, I want to print out from the 4th byte:
$ tail -c +4 animal.txt
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
5. -v: Filenames always show the beginning
$ tail -v animal.txt
6. –version: Check your version
$ tail --version
We just showed you how to use the tail command in Linux.
Thanks for reading!
Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications including CCNA RS, SCP, and ACE. As an IT engineer and technical author, he writes for various websites.