$linuxjunkies
>

head(1)

Output the first part of files.

UbuntuDebianFedoraArch

Synopsis

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

Description

Print the first 10 lines of each FILE to standard output. If multiple files are specified, each is preceded by a header showing the filename. If no FILE is given, or FILE is '-', read from standard input.

By default, head outputs 10 lines, but this can be changed with options to output a specific number of lines or bytes instead.

Common options

FlagWhat it does
-n NUMprint the first NUM lines instead of 10
-c NUMprint the first NUM bytes
-valways print filename headers, even for single file
-qnever print filename headers
-zuse null character as line delimiter instead of newline

Examples

Display the first 5 lines of the syslog file

head -n 5 /var/log/syslog

Show the first 100 bytes of myfile.txt

head -c 100 myfile.txt

Display first 6 lines of process list (header + 5 processes)

ps aux | head -n 6

Print the first line of each .txt file with headers

head -n 1 *.txt

Show first 20 lines from each of two log files

head -20 file1.log file2.log

Pipe output through head to limit to 50 lines

cat largefile.txt | head -n 50

Display all lines except the last 5 of the document

head -n -5 document.txt

Related commands