The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group


head - copy the first part of files


head [-n number][file...]

head [number][file...]


The head utility will copy its input files to the standard output, ending the output for each file at a designated point.

Copying will end at the point in each input file indicated by the -n number option (or the -number argument). The option-argument number will be counted in units of lines.


The head utility supports the XBD specification, Utility Syntax Guidelines  , except that the obsolescent version accepts multi-character numeric options.

The following options are supported:

-n number
The first number lines of each input file will be copied to standard output. The number option-argument must be a positive decimal integer.
The number argument is a positive decimal integer with the same effect as the -n number option.

If no options are specified, head will act as if -n 10 had been specified.


The following operand is supported:
A pathname of an input file. If no file operands are specified, the standard input will be used.


The standard input will be used only if no file operands are specified. See the INPUT FILES section.


Input files must be text files, but the line length is not restricted to {LINE_MAX} bytes.


The following environment variables affect the execution of head:
Provide a default value for the internationalisation variables that are unset or null. If LANG is unset or null, the corresponding value from the implementation-dependent default locale will be used. If any of the internationalisation variables contains an invalid setting, the utility will behave as if none of the variables had been defined.
If set to a non-empty string value, override the values of all the other internationalisation variables.
Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files).
Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
Determine the location of message catalogues for the processing of LC_MESSAGES .




The standard output will contain designated portions of the input files.

If multiple file operands are specified, head will precede the output for each with the header:

"\n==> %s <==\n", <pathname> except that the first header written will not include the initial newline character.


Used only for diagnostic messages.






The following exit values are returned:
Successful completion.
An error occurred.






To write the first ten lines of all files (except those with a leading period) in the directory:

head *


The obsolescent -number form may be withdrawn in a future issue. Applications should use the -n number option.


sed, tail.

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]