Linux and Unix tail command tutorial with examples

Linux and Unix tail command is one of the important command.

Command tail displays the bottom/end of the file at the terminal.

When “tail” command is used without any option it will display the bottom/end ten lines of the file.

Syntax of tail Command in Unix and Linux


Syntax:

Example of tail Command in Unix and Linux

Suppose we have a file Employee.txt as shown below and we want to display the bottom/end of this file.

By default tail command will display the bottom/end ten lines of the file.

Output

By default tail displayed bottom ten lies of file.

Options of tail command

tail -n option in Unix and Linux

Option (-n): potion “–n” is used to specify the number of lines to be display from bottom. Suppose we want to display the bottom 4 lines of file Employee.txt then the command is as follows:

Or

Output

Option (+ count): potion “+” is used to specify the line number from where the file to be displayed. Suppose we want to display line number 4 to onward of the file Employee.txt then the command is as follows:

Above command will display line number 4 to end of the file of file Employee.txt.

tail -f command option use and example in Unix and Linux

tail -f to show /var/log/auth.log updates

It will show real time file updated if any new entry added then it shows the updated data.

tail -f to show tomcat/logs/catalina.out updates

used to show real time updates in catalina.out

Show n lines with tail -f command

tail -f can be used with -n to show number of lines

tail -n0 -f Shows 0 lines with -f option

tail -n5 -f shows 5 lines with -f option

Tail -f output with line number

tail -f | nl display the file content with line number.

Searching Pattern Using tail -f and grep

we can use grep with tail -f to search specific pattern

Reference

tail -f

tail(1) – Linux man page

Read More

Linux and Unix head command tutorial with examples
Linux and Unix sort command tutorial with examples