Command head displays the beginning/top of the file at the terminal.
When “head” command is used without any option it will display the beginning/top ten lines of the file.
Syntax:
1 | $ head filename [press enter] |
Example:
Suppose we have a file Employee.txt as shown below and we want to see the beginning/top of this file by default it will display the beginning/top ten lines of the file.
File 1: Employee.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | $ head Employee.txt [press enter] <pre brush="text"> <strong>Output</strong> <pre brush="text"> Bank For Indians Bhilai Chattisgarh Date: 11/12/17 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 | |
Options of head command
Line count option (-n): potion “–n” is used to specify the number of lines to be display. Suppose we want to display the top 4 lines of file Employee.txt then the command is as follows:
1 | $ head -n 4 Employee.txt [press enter] |
Or
1 | $ head 4 Employee.txt [press enter] (On some system) |
Output
1 2 3 4 | Bank For Indians Bhilai Chattisgarh Date: 11/12/17 Employee Details |