Linux Head

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

Linux head command

The 'head' command displays the starting content of a file. By default, it displays starting 10 lines of any file.


head <file name> 


  1. head jtp.txt  

Linux Head1

Look at the above snapshot, command "head jtp.txt" has displayed the first ten lines of the file 'jtp.txt'.

Head command for multiple files

If we'll write two file names then it will display first ten lines (in this case file has five lines only) of each file separated by a heading.


  1. head <file name> <file name>  


head doc1.txt doc2.txt 

Linux Head2

Look at the above snapshot, content of both the files are displayed with a separate heading with the help of "head doc1.txt doc2.txt" command.

Linux head -n

The 'head -n' option displays specified number of lines.


  1. head -n <file name>  


  1. head -15 jtp.txt  

Linux head-n

Look at the above snapshot, 15 lines are displayed by the command "head -15 jtp.txt".

Note: The above example syntax can also be written as "head -n15 jtp.txt" or "head -n 15 jtp.txt". In all cases result will be same.

Linux head -c

The 'head -c' command counts the number of bytes of a file.


  1. head -c <number> <file name>  


  1. head -c 20 jtp.txt  

Linux head-c

Look at the above snapshot, 20 byte content of file 'jtp.txt' is displayed with the help of command "head -c 20 jtp.txt".

Note: Bytes counting has only one syntax unlike lines counting.

If you'll use "head -ck "then it will return the result by multiplying the number by suffix. Suffix can be "b (bytes=512), k(kilobytes=1024) and m (megabytes=1048576)".