head(1)

head1

Display first lines of a file

Usage

head [{-n count | -c bytes}] [file ...]

Overview

This filter displays the first count lines or bytes of each of the specified files, or of the standard input if no files are specified. If count is omitted it defaults to 10.

The following options are available:

-c bytes, --bytes=bytes

Print bytes of each of the specified files.

-n count, --lines=count

Print count lines of each of the specified files.

If more than a single file is specified, each file is preceded by a header consisting of the string “==> XXX <==” where “XXX” is the name of the file.

Exit status

The head utility exits 0 on success, and >0 if an error occurs.

Examples

To display the first 500 lines of the file foo:

$ head -n 500 foo

head can be used in conjunction with tail(1) in the following way to, for example, display only line 500 from the file foo:

$ head -n 500 foo | tail -n 1

Releases

163 releases since Mac OS X 10.0; the text changed 2 times.

  1. 10.0–10.4.11
  2. 10.5–11.5
  3. 12.0.1–26.5

--bytes since macOS 12.0.1; --lines since macOS 12.0.1; -c since macOS 12.0.1; -n since macOS 12.0.1.

History

The head command appeared in PWB UNIX.

From text_cmds 199 in macOS 26.5. Parsed by carta from the page's mdoc source.