1HEAD(1P) POSIX Programmer's Manual HEAD(1P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 head — copy the first part of files
13
15 head [-n number] [file...]
16
18 The head utility shall copy its input files to the standard output,
19 ending the output for each file at a designated point.
20
21 Copying shall end at the point in each input file indicated by the -n
22 number option. The option-argument number shall be counted in units of
23 lines.
24
26 The head utility shall conform to the Base Definitions volume of
27 POSIX.1‐2017, Section 12.2, Utility Syntax Guidelines.
28
29 The following option shall be supported:
30
31 -n number The first number lines of each input file shall be copied to
32 standard output. The application shall ensure that the number
33 option-argument is a positive decimal integer.
34
35 When a file contains less than number lines, it shall be copied to
36 standard output in its entirety. This shall not be an error.
37
38 If no options are specified, head shall act as if -n 10 had been speci‐
39 fied.
40
42 The following operand shall be supported:
43
44 file A pathname of an input file. If no file operands are speci‐
45 fied, the standard input shall be used.
46
48 The standard input shall be used if no file operands are specified, and
49 shall be used if a file operand is '-' and the implementation treats
50 the '-' as meaning standard input. Otherwise, the standard input shall
51 not be used. See the INPUT FILES section.
52
54 Input files shall be text files, but the line length is not restricted
55 to {LINE_MAX} bytes.
56
58 The following environment variables shall affect the execution of head:
59
60 LANG Provide a default value for the internationalization vari‐
61 ables that are unset or null. (See the Base Definitions vol‐
62 ume of POSIX.1‐2017, Section 8.2, Internationalization Vari‐
63 ables for the precedence of internationalization variables
64 used to determine the values of locale categories.)
65
66 LC_ALL If set to a non-empty string value, override the values of
67 all the other internationalization variables.
68
69 LC_CTYPE Determine the locale for the interpretation of sequences of
70 bytes of text data as characters (for example, single-byte as
71 opposed to multi-byte characters in arguments and input
72 files).
73
74 LC_MESSAGES
75 Determine the locale that should be used to affect the format
76 and contents of diagnostic messages written to standard
77 error.
78
79 NLSPATH Determine the location of message catalogs for the processing
80 of LC_MESSAGES.
81
83 Default.
84
86 The standard output shall contain designated portions of the input
87 files.
88
89 If multiple file operands are specified, head shall precede the output
90 for each with the header:
91
92
93 "\n==> %s <==\n", <pathname>
94
95 except that the first header written shall not include the initial
96 <newline>.
97
99 The standard error shall be used only for diagnostic messages.
100
102 None.
103
105 None.
106
108 The following exit values shall be returned:
109
110 0 Successful completion.
111
112 >0 An error occurred.
113
115 Default.
116
117 The following sections are informative.
118
120 When using head to process pathnames, it is recommended that LC_ALL, or
121 at least LC_CTYPE and LC_COLLATE, are set to POSIX or C in the environ‐
122 ment, since pathnames can contain byte sequences that do not form valid
123 characters in some locales, in which case the utility's behavior would
124 be undefined. In the POSIX locale each byte is a valid single-byte
125 character, and therefore this problem is avoided.
126
128 To write the first ten lines of all files (except those with a leading
129 period) in the directory:
130
131
132 head -- *
133
135 Although it is possible to simulate head with sed 10q for a single
136 file, the standard developers decided that the popularity of head on
137 historical BSD systems warranted its inclusion alongside tail.
138
139 POSIX.1‐2008 version of head follows the Utility Syntax Guidelines. The
140 -n option was added to this new interface so that head and tail would
141 be more logically related. Earlier versions of this standard allowed a
142 -number option. This form is no longer specified by POSIX.1‐2008 but
143 may be present in some implementations.
144
145 There is no -c option (as there is in tail) because it is not histori‐
146 cal practice and because other utilities in this volume of POSIX.1‐2017
147 provide similar functionality.
148
150 None.
151
153 sed, tail
154
155 The Base Definitions volume of POSIX.1‐2017, Chapter 8, Environment
156 Variables, Section 12.2, Utility Syntax Guidelines
157
159 Portions of this text are reprinted and reproduced in electronic form
160 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
161 table Operating System Interface (POSIX), The Open Group Base Specifi‐
162 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
163 Electrical and Electronics Engineers, Inc and The Open Group. In the
164 event of any discrepancy between this version and the original IEEE and
165 The Open Group Standard, the original IEEE and The Open Group Standard
166 is the referee document. The original Standard can be obtained online
167 at http://www.opengroup.org/unix/online.html .
168
169 Any typographical or formatting errors that appear in this page are
170 most likely to have been introduced during the conversion of the source
171 files to man page format. To report such errors, see https://www.ker‐
172 nel.org/doc/man-pages/reporting_bugs.html .
173
174
175
176IEEE/The Open Group 2017 HEAD(1P)