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:
1 | $ tail filename [press enter] |
Example:
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.
1 | $ tail Employee.txt [press enter] |
Output
1 2 3 4 5 6 7 8 9 10 | Employee Details Name | Post | Salary | DOB | Age | Aditya | DGM | 100000 | 03-02-1987 | 30 | Kumar | GM | 700000 | 05-02-1977 | 41 | Manish | CA | 500000 | 10-02-1997 | 20 | Rajeev | CLERK | 300000 | 05-05-1987 | 31 | Ashok | DGM | 800000 | 03-12-1977 | 40 | Satwant | GM | 500000 | 05-02-1997 | 21 | Jack | CA | 600000 | 10-12-1990 | 28 | Bharat | CLERK | 400000 | 04-03-1987 | 31 | |
By default tail displayed bottom ten lies of file.
Options of tail command
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:
1 | $ tail -n 4 Employee.txt [press enter] |
Or
1 | $ tail 4 Employee.txt [press enter] (On some system) |
Output
1 2 3 4 | Ashok | DGM | 800000 | 03-12-1977 | 40 | Satwant | GM | 500000 | 05-02-1997 | 21 | Jack | CA | 600000 | 10-12-1990 | 28 | Bharat | CLERK | 400000 | 04-03-1987 | 31 | |
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:
1 | $ tail + 4 Employee.txt [press enter] |
Above command will display line number 4 to end of the file of file Employee.txt.