manpagez: man pages & more
info coreutils
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.1 head: Output the first part of files

head prints the first part (10 lines by default) of each file; it reads from standard input if no files are given or when given a file of ‘-’. Synopsis:

head [option]… [file]…

If more than one file is specified, head prints a one-line header consisting of:

==> file name <==

before the output for each file.

The program accepts the following options. Also see Common options.

-c n

Print the first n bytes, instead of initial lines. However, if n starts with a ‘-’, print all but the last n bytes of each file. Appending ‘b’ multiplies n by 512, ‘kB’ by 1000, ‘K’ by 1024, ‘MB’ by 1000*1000, ‘M’ by 1024*1024, ‘GB’ by 1000*1000*1000, ‘GB’ by 1024*1024*1024, and so on for ‘T’, ‘P’, ‘E’, ‘Z’, and ‘Y’.

-n n

Output the first n lines. However, if n starts with a ‘-’, print all but the last n lines of each file. Size multiplier suffixes are the same as with the ‘-c’ option.


Never print file name headers.


Always print file name headers.

For compatibility head also supports an obsolete option syntax ‘-countoptions’, which is recognized only if it is specified first. count is a decimal number optionally followed by a size letter (‘b’, ‘k’, ‘m’) as in ‘-c’, or ‘l’ to mean count by lines, or other option letters (‘cqv’). Scripts intended for standard hosts should use ‘-c count’ or ‘-n count’ instead. If your script must also run on hosts that support only the obsolete syntax, it is usually simpler to avoid head, e.g., by using ‘sed 5q’ instead of ‘head -5’.

An exit status of zero indicates success, and a nonzero value indicates failure.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]
© 2000-2021
Individual documents may contain additional copyright information.