HEAD(1) General Commands Manual Fully-rendered PDF

headextract file header

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

Copies the first lines (default 10) or bytes of each file (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), dd(1), truncate(1).

tail(1) — ‘-’-marked lines and bytes are symmetric, and ‘+’-marked ones are almost symmetric:

{ head -c -10 f; tail -c -10 f; }
{ head -n +10 f; tail -n +11 f; }
are equivalent to cat f.

Conforms to IEEENoStd1003.1-2024PoDoTn.ENPOSIXNs.1DcPc;.Flzqv,negativeandunit-suffixed.Arlinesand.Arbytesareextensions,originatingtheGNUsystem..Flqv_.Fx3.0..PpTheGNUsystemdisallows.Arlinesand.Arbyteswith.SyBbutwithoutamultiplierandonlysupportsinteger.VabaseNss..PpAheretofore-unnotedlegacy.FlNsArlinesargumentformat,equivalent.FlnArlines,isalsoaccepted,forcompatibilitywith.Bx1.Avoidit....ShHISTORY.Appearedmostlyfully-formedin.Bx1as.XrheadVI:.D1head [ -count ] [ file ... ] with.ArcountNssinterspersableamong.ArfileNss..Pp.Bx4.3Renofixesthis,onlyallowingitasthefirstargument..Pp.Bx4.4adds.FlnArlinesandprunes.FlNsArlinesthemanual..Pp.AtV.4sees.Bx2.Nm..Pp.St-p1003.2-92standardisesboth.Arlinesforms,havingcreated.Flnmatch.Nmtail,butnotesthe.FlNsArlinesoneasobsolescent.It'sremovedin.St-p1003.1-2001..Pp.St-p1003.1-2024standardisesplain-number.FlcArbytes...EQ

July 7, 2024 voreutils 5a9f9f29