The head command

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

The head command prints the first ten lines of a file.

[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]# head 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
[root@academy F1]#

Syntax:

head [OPTION] [FILENAME]

Get a specific number of lines:

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

[root@academy F1]# head -n 5 myfile.txt
Line 1 : content 1
Line 2 : content 2
Line 3 : content 3
Line 4 : content 4
Line 5 : content 5
[root@academy F1]#

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

Syntax:

head -n <number> myfile.txt

Additional Flags and their Functionalities

Last updated