Skip Navigation Bar
NLM logo

head/tail


Please note: following the release of the new version of PubMed, the results returned by E-utilities queries of PubMed may differ slightly from those returned in the web version of PubMed. A new PubMed API is currently under development: more information will be announced when available.

As new Insider's Guide classes are no longer being offered, this site is not currently being updated. Please refer to NCBI's E-utilities documentation for more up-to-date information.


The head and tail commands restrict output to only the first or last portion (10 lines by default) of the input, respectively.

To see a full list of arguments, options, and features of head, see the head documentation page, or type

man head

into your terminal to see the manual page for head.

To see a full list of arguments, options, and features of tail, see the tail documentation page, or type

man tail

into your terminal to see the manual page for tail.

Input

Multiple lines of text, either piped in from a previous command, or in a file.

Output

For the head command, the first portion of the input.

For the tail command, the last portion of the input.

How large a portion is output is determined by the arguments and options selected.

Using head

By default, the head command outputs only the first 10 lines of the input.

head

You can adjust the number of lines to be returned using the -n argument. For example:

head -n 15

outputs the first 15 lines of the input.

The head command can also output all but the last portion of the input, if the number of lines is prefixed by a “-”. For example:

head -n -10

outputs the entire input file, with the exception of the last 10 lines.

Using tail

By default, the tail command outputs only the last 10 lines of the input.

tail

You can adjust the number of lines to be returned using the -n argument. For example:

tail -n 15

outputs the last 15 lines of the input.

The tail command can also output all but the first portion of the input, if the number of lines is prefixed by a “-”. For example:

tail -n -10

outputs the entire input file, with the exception of the first 10 lines.

Last Reviewed: August 9, 2021