HEAD(1) General Commands Manual HEAD(1)

headextract file header

head [-zqv] [-n [-]lines] [-c [-]bytes] [file]…

Copies the first lines (default 10) or bytes of each file (the standard input stream if "-", the default) to the standard output stream.

With more than one file, each one is delineated by an empty line and

==> file <==
heading.

If lines or bytes start with a -, all the last lines or bytes of the files are copied.

lines and bytes are in the mostly-case-insensitive format:

[base][b|KMGTPEZY[B]] (with at least one of {base, b, KMGTPEZY, B})
Where base is an optionally-floating-point number of bytes, defaulting to 1, which is then optionally multiplied by the relevant unit. B sets the unit multiplier to (from ). b(lock) is a unit of . lines|bytes is equal to base·unitmult , if any, or base.

, --lines= lines
Copy the first lines of each file. Default: 10.
, --bytes= bytes
Copy the first bytes of each file.
, --lines=-lines
Copy all but the last lines of each file.
, --bytes=-bytes
Copy all but the last bytes of each file.

, --zero-terminated
Line separator is NUL, not newline. File headers are still written with newlines.
, --quiet, --silent
Never write file headers.
, --verbose
Always write file headers.

1 if a file couldn't be opened or read.

$ find tests/ -type f -executable -exec head -n2 {} +
==> tests/head <==
#!/bin/sh
# SPDX-License-Identifier: 0BSD

==> tests/env/test <==
#!/bin/sh
# SPDX-License-Identifier: 0BSD

==> tests/env/code/env.1-3c <==
#!/usr/bin/env -S PYTHONUNBUFFERED=1 python3 -S
echo "PYTHONUNBUFFERED=$PYTHONUNBUFFERED"


# Strip signature generated by Linux sign-file
$ head -c-754 /lib/modules/$(uname -r)/updates/dkms/zfs.ko

cat(1), tail(1)

Conforms to IEEE Std 1003.1-2008 (“POSIX.1”); -czqv, "negative" and unit-suffixed lines and bytes are extensions, originating from the GNU system. -c is also available under FreeBSD 4.0 and -qvc under FreeBSD 3.0.

The GNU system disallows lines and bytes with B but without a multiplier and only supports integer bases.

A heretofore-unnoted legacy -lines argument format, equivalent to -n lines, is also accepted, for compatibility with 1BSD. Avoid it.

Appeared mostly fully-formed in 1BSD as head(VI):

head [ -count ] [ file ... ]
with counts interspersable among files.

4.3BSD-Reno fixes this, only allowing it as the first argument.

4.4BSD adds -n lines and prunes -lines from the manual.

AT&T System V Release 4 UNIX sees 2BSD head.

IEEE Std 1003.2-1992 (“POSIX.2”) standardises both lines forms, having created -n to match tail, but notes the -lines one as obsolescent. It's removed in IEEE Std 1003.1-2001 (“POSIX.1”).

June 6, 2023 voreutils pre-v0.0.0-latest