Name

head — stdin  stdout  - file  -- opt  --help  --version

Synopsis

head [options] [files]

The head command prints the first 10 lines of a file: great for previewing the contents of a file:

head myfile

or of many files, with a convenient header in front of each:

head * | less      Preview all files in the current directory

or the first few lines of output from a pipeline. Here we use the grep command (see File Text Manipulation), which locates matching lines in a file, to print all lines containing a capital E. by piping the output to head, we display only the first 10 matches:

grep 'E' very-big-file | head

Useful options

-N

Print the first N lines instead of 10.

-n N

Print the first N lines instead of 10.

-c N

Print the first N bytes of the file.

Get Macintosh Terminal Pocket Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.