The tail command

Yaser Rahmati | یاسر رحمتی

The tail command prints the last ten lines of a file.

Example:

[root@academy F1]# cat myfile.txt
Line 1 : content 1
Line 2 : content 2
Line 3 : content 3
Line 4 : content 4
Line 5 : content 5
Line 6 : content 6
Line 7 : content 7
Line 8 : content 6
line 9 : content 9
Line 10: content 10
Line 11: content 11
Line 12: content 12
[root@academy F1]# tail myfile.txt
Line 3 : content 3
Line 4 : content 4
Line 5 : content 5
Line 6 : content 6
Line 7 : content 7
Line 8 : content 6
line 9 : content 9
Line 10: content 10
Line 11: content 11
Line 12: content 12
[root@academy F1]#

Syntax:

tail [OPTION] [FILENAME]

Get a specific number of lines with tail:

Use the -n option with a number(should be an integer) of lines to display.

[root@academy F1]# tail -n 5 myfile.txt
Line 8 : content 6
line 9 : content 9
Line 10: content 10
Line 11: content 11
Line 12: content 12
[root@academy F1]#

This command will display the last five lines of the file myfile.txt.

Refresh the output on any new entry in a file

It is possible to let tail output any new line added to the file you are looking into. So, if a new line is written to the file, it will immediately be shown in your output. This can be done using the --follow or -f option. This is especially useful for monitoring log files.

Syntax:

tail -n <number> foo.txt

Additional Flags and their Functionalities

Last updated