Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

head - copy the first part of files

&pagelevel(4)&pagelevel

head copies the opening lines of a file to standard output. If no file is given, head reads from standard input.


Syntax


Format 1:head[ -n number][ file]
Format 2:head[ -number][ file]



Format 1:head[ -n number][ file]


-n number

Number of lines to be output. number must be a positive decimal number. The space between -n and number is optional.
-n number not specified:
The first 10 lines are output.

file

Name of the input file. If more than one file is named, the files will be processed in the order in which they are listed, and the output of each file begins with:
==>file<==


Format 2:head[ -number][ file]


-number

Number of lines to be output. number must be a positive decimal number.
-n number not specified:
The first 10 lines are output.

file

Name of the input file. If more than one file is named, the files will be processed in the order in which they are listed, and the output of each file begins with:
==>file<==

Locale

The following environment variables affect the execution of head:

LANG

Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization 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 internationalization 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), the classification of characters as upper- to lower-case, and the mapping of characters from one case to the other.

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 catalogs for the processing of LC_MESSAGES.

Example

To see the first 5 lines of three files, you enter the head command as shown below:

$ head -5 file1 file2 file3

The first five lines of each of the three files are written to standard output as follows:

==>file1<==
Lines 1-5 of file 1
==>file2<==
Lines 1-5 of file 2
==>file3<==
Lines 1-5 of file 3

See also

cat, more, tail