Skip to content
HxHippy

head

Output the first part of files

Overview

Prints the first 10 lines of each FILE to standard output. With more than one FILE, precede each with a header giving the file name.

Syntax

head [OPTION]... [FILE]...

Common Options

-n, --lines=[-]K

Print the first K lines instead of the first 10. With a leading '-' print all but the last K lines of each file.

-c, --bytes=[-]K

Print the first K bytes of each file. With a leading '-' print all but the last K bytes of each file. (K may have a multiplier: b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024, etc.)

-q, --quiet, --silent

Never print headers giving file names.

-v, --verbose

Always print headers giving file names.

Examples

$ head myfile.txt

Displays the first 10 lines of myfile.txt.

$ head -n 5 access.log

Displays the first 5 lines of access.log.

$ head -n -5 data.csv

Displays all lines of data.csv except for the last 5 lines.

$ head -c 100 /dev/urandom

Displays the first 100 bytes from /dev/urandom.

$ ls -t | head -n 3

Lists files and sorts them by modification time (newest first) and shows the newest 3.

headbeginningfirstlinesfiletexttop