Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Head (Unix)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{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 <code>head</code> command to display first 5 lines of [[Lorem ipsum]] in the specified file | author = | developer = Various [[open-source software|open-source]] and [[commercial software|commercial]] developers | released = | latest release version = | latest release date = | operating system = [[Unix]], [[Unix-like]], [[MSX-DOS]], [[IBM i]] | platform = [[Cross-platform]] | genre = [[Command (computing)|Command]] | license = [[coreutils]]: [[GPLv3]] | website = }} '''{{code|head}}''' is a [[Computer program|program]] on [[Unix]] and [[Unix-like]] [[operating system]]s used to display the beginning of a text [[Computer file|file]] or [[pipe (computing)|pipe]]d 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 <code>n</code> and instead directly specifying the number: <code>-5</code>. [[GNU]] head allows negative arguments for the <code>-n</code> 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.<ref>{{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}}</ref> ==Implementations== A <code>head</code> command is also part of [[ASCII Corporation|ASCII]]'s ''MSX-DOS2 Tools'' for [[MSX-DOS]] version 2.<ref>[https://archive.org/details/MSXDOS2TOOLS MSX-DOS2 Tools User's Manual by ASCII Corporation]</ref> The {{Mono|head}} command has also been ported to the [[IBM i]] operating system.<ref>{{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 }}</ref> ==See also== *[[tail (Unix)]] *[[dd (Unix)]] *[[List of Unix commands]] ==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]] [[Category:Unix SUS2008 utilities]] [[Category:IBM i Qshell commands]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Angbr
(
edit
)
Template:Cite journal
(
edit
)
Template:Cite web
(
edit
)
Template:Code
(
edit
)
Template:Core Utilities commands
(
edit
)
Template:Defn
(
edit
)
Template:Glossary
(
edit
)
Template:Glossary end
(
edit
)
Template:Infobox
(
edit
)
Template:Infobox software
(
edit
)
Template:Lowercase
(
edit
)
Template:Main other
(
edit
)
Template:Mono
(
edit
)
Template:More citations needed
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Sister project
(
edit
)
Template:Template other
(
edit
)
Template:Term
(
edit
)
Template:Tt
(
edit
)
Template:Unix commands
(
edit
)
Template:Wikibooks
(
edit
)