Head Command – UNIX

Head Command UNIX

Description

Head command is use to print the number of lines specified with command from beginning of the file.

If number of lines are not mentioned with the command, then 10 lines from the beginning are displayed on terminal.

Options

Following options can be used with the head command:

-c, –bytes=[-]K print the first K bytes of each file; with the leading ‘-‘, print all but the last K bytes of each file
-n, –lines=[-]K print the first K lines instead of the first 10; with the leading ‘-‘, print all but the last K lines of each file
-q, –quiet, –silent never print headers giving file names
-v, –verbose always print headers giving file names
–help display this help and exit
–version output version information and exit

Examples

Example 1:

Print 3 lines of file “CF0001.dat” on terminal.

$ head -3 CF0001.dat
9555777241:9841723417:20160318:20:Rupees
55777242:9841723418:20160318:25:Dollar
5777243:9841723419:20160318:18:Rupees
$