HEAD(1POSIX)
π PROLOG π
okay bestie, real talk before we even get into it: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ β so pls go consult the corresponding Linux manual page for the deets on Linux behavior β or honestly, the interface may not even be implemented on Linux at all. π no cap. check first.
β¨ NAME β¨
head β copy the first part of files π«Ά
π¦ SYNOPSIS π¦
head [-n number] [file...]
πΈ DESCRIPTION πΈ
So here's the vibe: the head utility shall copy its input files to the standard output, ending the output for each file at a designated point. it's giving "sneak peek" energy. π
Copying shall end at the point in each input file indicated by the -n number option. And the option-argument number shall be counted in units of lines. periodt.
π OPTIONS π
The head utility shall conform to the Base Definitions volume of POSIX.1β2017, Section 12.2, Utility Syntax Guidelines. (yes she plays by the rules, she's a good girl π)
The following option shall be supported:
-nnumber β The first number lines of each input file shall be copied to standard output. The application shall ensure that the number option-argument is a positive decimal integer. (not me being picky about it but fr fr, positive. decimal. integer. no funny business. β)
When a file contains less than number lines, it shall be copied to standard output in its entirety. And this shall not be an error. no drama, it's fine, everything's fine. π
If no options are specified, head shall act as if -n 10 had been specified. iconic default behavior tbh. π
π OPERANDS π
The following operand shall be supported:
- file β A pathname of an input file. If no file operands are specified, the standard input shall be used. (so if u give her nothing she just reads from stdin, lowkey relatable π«Ά)
π STDIN π
The standard input shall be used if no file operands are specified, and shall be used if a file operand is '-' and the implementation treats the '-' as meaning standard input. Otherwise, the standard input shall not be used. See the INPUT FILES section. iykyk. β¨
π§ INPUT FILES π§
Input files shall be text files, but the line length is not restricted to {LINE_MAX} bytes. she can handle long lines, she's flexible like that π
π ENVIRONMENT VARIABLES π
The following environment variables shall affect the execution of head:
LANGβ Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of POSIX.1β2017, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.)LC_ALLβ If set to a non-empty string value, override the values of all the other internationalization variables. (she's the main character, she overrides everyone π)LC_CTYPEβ Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments and input files).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 ofLC_MESSAGES.
β‘ ASYNCHRONOUS EVENTS β‘
Default. (she said "no thoughts, head empty" π)
π STDOUT π
The standard output shall contain designated portions of the input files. β¨
If multiple file operands are specified, head shall precede the output for each with the header:
"\n==> %s <==\n", <pathname>
except that the first header written shall not include the initial <newline>. (so the very first one is fresh-faced, no leading newline. the rest get the glow-up. π
)
π STDERR π
The standard error shall be used only for diagnostic messages. that's it. that's her lane.
π OUTPUT FILES π
None. (empty. void. nothing. not a single file. π¦)
β EXTENDED DESCRIPTION β
None. (again, nothing. she's simple, she's clean. π)
π₯ EXIT STATUS π₯
The following exit values shall be returned:
0β Successful completion. slay. β>0β An error occurred. π
π CONSEQUENCES OF ERRORS π
Default.
The following sections are informative.
πΈ APPLICATION USAGE πΈ
When using head to process pathnames, it is recommended that LC_ALL, or at least LC_CTYPE and LC_COLLATE, are set to POSIX or C in the environment, since pathnames can contain byte sequences that do not form valid characters in some locales, in which case the utility's behavior would be undefined. (bestie. undefined behavior. we do not do that. π)
In the POSIX locale each byte is a valid single-byte character, and therefore this problem is avoided. so like, set ur locales, it's not hard, and everything is chill. π«Ά
π§ EXAMPLES π§
To write the first ten lines of all files (except those with a leading period) in the directory:
head -- *
(iconic. the -- is doing so much work here and honestly? we love her. β¨)
π RATIONALE π
Although it is possible to simulate head with sed 10q for a single file, the standard developers decided that the popularity of head on historical BSD systems warranted its inclusion alongside tail. (the girls were literally begging for it. so they added it. periodt. π
)
The POSIX.1β2008 version of head follows the Utility Syntax Guidelines. The -n option was added to this new interface so that head and tail would be more logically related. Earlier versions of this standard allowed a -number option. This form is no longer specified by POSIX.1β2008 but may be present in some implementations. so like, if u see it somewhere, don't be shook. π
There is no -c option (as there is in tail) because it is not historical practice and because other utilities in this volume of POSIX.1β2017 provide similar functionality. no -c besties, sorry, she doesn't have that one. π
π¦ FUTURE DIRECTIONS π¦
None. (the future is bright and it is empty. β)
π SEE ALSO π
sedtail- The Base Definitions volume of POSIX.1β2017, Chapter 8, Environment Variables, Section 12.2, Utility Syntax Guidelines
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole thing, bestie!! π«Ά this page came to u from the IEEE/The Open Group, dated 2017, and it's HEAD(1POSIX) from the POSIX Programmer's Manual. go forth and copy the first part of files. slay. β¨ππ
π¦ where this page comes from
- debian bookworm: manpages-posix 2017a-2 Β· Other
- debian trixie: manpages-posix 2017a-2 Β· Other
- ubuntu jammy: manpages-posix 2017a-2 Β· Other
- ubuntu noble: manpages-posix 2017a-2 Β· Other
- ubuntu resolute: manpages-posix 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms