Text processing

Linux head command

Show the first lines of a file; use -n to choose how many.

Availability: Common Linux commands; shell built-ins and external implementations may differ by distribution.中文

Syntax

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

Examples

Show the first 20 lines of a log.

head -n 20 app.log

Inspect the first 64 bytes of a file.

head -c 64 image.bin

Parameters, options and clauses

Option / clauseDescription
-n, --lines=NUMPrint the first NUM lines (default 10).
-c, --bytes=NUMPrint the first NUM bytes.
-q, --quietNever print file headers.
-v, --verboseAlways print file headers.
-z, --zero-terminatedTreat NUL, rather than newline, as the line delimiter.
Safety note

Review a command and its target before running it. Commands that alter files, services, accounts, disks, permissions or databases may be difficult to reverse. Test in a safe environment and keep backups.

Official reference ↗Back to directory