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.
- -number
- 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:
- file
- 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:
- LANG
- 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.
- LC_ALL
- If set to a non-empty string value, override the values of all the other internationalisation variables.
- LC_CTYPE
- 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).
- LC_MESSAGES
- Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
- NLSPATH
- Determine the location of message catalogues for the processing of LC_MESSAGES .
Default.
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.
None.
None.
The following exit values are returned:
- 0
- Successful completion.
- >0
- An error occurred.
Default.
None.
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.