head (Unix)
{{more citations needed|date=June 2020}}
{{short description|Program on Unix and Unix-like systems}}
{{lowercase}}
{{Infobox software
| name = head
| logo =
| screenshot = Head-example-command.gif
| screenshot size =
| caption = Example usage of head
command to display first 5 lines of Lorem ipsum in the specified file
| author =
| developer = Various open-source and commercial developers
| released =
| latest release version =
| latest release date =
| operating system = Unix, Unix-like, MSX-DOS, IBM i
| platform = Cross-platform
| genre = Command
| website =
}}
{{code|head}} is a program on Unix and Unix-like operating systems used to display the beginning of a text file or piped data.
Syntax
The command syntax is:
head [options] {{angbr|file_name}}
By default, {{tt|head}} will print the first 10 lines of its input to the standard output.
=Option flags=
{{glossary}}
{{term|1=-n|2={{tt|-n}} {{angbr|count}}}}
{{term|1=--lines|2={{tt|--lines}}={{angbr|count}}}}
{{defn|1=
The number of lines printed may be changed with a command line option. The following example shows the first 20 lines of filename:
{{pre|head -n 20 filename}}
This displays the first 5 lines of all files starting with foo:
{{pre|head -n 5 foo*}}
Most versions{{citation needed|date=June 2020}} allow omitting n
and instead directly specifying the number: -5
. GNU head allows negative arguments for the -n
option, meaning to print all but the last - argument value counted - lines of each input file.
}}
{{term|1=-c|2={{tt|-c}} {{angbr|bytes}}}}
{{term|1=--bytes|2={{tt|--bytes}}={{angbr|bytes}}}}
{{defn|Print first x number of bytes.}}
{{glossary end}}
Other command
Many early versions of Unix and Plan 9 did not have this command, and documentation and books used sed instead:
sed 5q filename
The example prints every line (implicit) and quits after the fifth.
Equivalently, awk may be used to print the first five lines in a file:
awk 'NR < 6' filename
However, neither sed nor awk were available in early versions of BSD, which were based on
Version 6 Unix, and included head.{{cite journal |last1=Spinellis |first1=Diomidis
|title=dspinellis/unix-history-man: Version 1.0 web pages (v1.1-web)
|journal=Zenodo |date=2022 |doi=10.5281/zenodo.7248228
|url=https://dspinellis.github.io/unix-history-man/man1.html}}
Implementations
A head
command is also part of ASCII's MSX-DOS2 Tools for MSX-DOS version 2.[https://archive.org/details/MSXDOS2TOOLS MSX-DOS2 Tools User's Manual by ASCII Corporation] The {{Mono|head}} command has also been ported to the IBM i operating system.{{cite web |title=IBM System i Version 7.2 Programming Qshell |language=en |author=IBM |author-link=IBM |url=https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzahz/rzahzpdf.pdf?view=kc |access-date=2020-09-05 }}
See also
References
{{Reflist}}
External links
{{Wikibooks|Guide to Unix|Commands}}
- [https://www.gnu.org/software/coreutils/manual/html_node/head-invocation.html head] manual page from GNU coreutils.
- [http://www.freebsd.org/cgi/man.cgi?query=head&apropos=0&sektion=0&manpath=FreeBSD+5.3-RELEASE+and+Ports&format=html FreeBSD documentation for head]
{{Unix commands}}
{{Core Utilities commands}}
Category:Unix text processing utilities