head Command: Tutorial & Examples
Display the first few lines of a file
The head command is a utility that is used to display the first few lines of a text file. It is the opposite of the
tail command, which displays the last few lines of a file.
To view the first 10 lines of a file with head, simply type head followed by the name of the file:
You can use the
-n flag followed by a number to specify the number of lines to display:
head -n 20 file.txt
This will display the first 20 lines of the file.
head is a simple and useful tool for quickly viewing the beginning of a text file on a Linux system. It is often used in combination with other commands,
less, to filter and process the output of those commands before viewing it in head.