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
11
13 head — copy the first part of files
14
16 head [−n number] [file...]
17
19 The head utility shall copy its input files to the standard output,
20 ending the output for each file at a designated point.
21
22 Copying shall end at the point in each input file indicated by the −n
23 number option. The option-argument number shall be counted in units of
24 lines.
25
27 The head utility shall conform to the Base Definitions volume of
28 POSIX.1‐2008, Section 12.2, Utility Syntax Guidelines.
29
30 The following option shall be supported:
31
32 −n number The first number lines of each input file shall be copied to
33 standard output. The application shall ensure that the number
34 option-argument is a positive decimal integer.
35
36 When a file contains less than number lines, it shall be copied to
37 standard output in its entirety. This shall not be an error.
38
39 If no options are specified, head shall act as if −n 10 had been speci‐
40 fied.
41
43 The following operand shall be supported:
44
45 file A pathname of an input file. If no file operands are speci‐
46 fied, the standard input shall be used.
47
49 The standard input shall be used if no file operands are specified, and
50 shall be used if a file operand is '−' and the implementation treats
51 the '−' as meaning standard input. Otherwise, the standard input shall
52 not be used. See the INPUT FILES section.
53
55 Input files shall be text files, but the line length is not restricted
56 to {LINE_MAX} bytes.
57
59 The following environment variables shall affect the execution of head:
60
61 LANG Provide a default value for the internationalization vari‐
62 ables that are unset or null. (See the Base Definitions vol‐
63 ume of POSIX.1‐2008, Section 8.2, Internationalization Vari‐
64 ables for the precedence of internationalization variables
65 used to determine the values of locale categories.)
66
67 LC_ALL If set to a non-empty string value, override the values of
68 all the other internationalization variables.
69
70 LC_CTYPE Determine the locale for the interpretation of sequences of
71 bytes of text data as characters (for example, single-byte as
72 opposed to multi-byte characters in arguments and input
73 files).
74
75 LC_MESSAGES
76 Determine the locale that should be used to affect the format
77 and contents of diagnostic messages written to standard
78 error.
79
80 NLSPATH Determine the location of message catalogs for the processing
81 of LC_MESSAGES.
82
84 Default.
85
87 The standard output shall contain designated portions of the input
88 files.
89
90 If multiple file operands are specified, head shall precede the output
91 for each with the header:
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 None.
121
123 To write the first ten lines of all files (except those with a leading
124 period) in the directory:
125
126 head −− *
127
129 Although it is possible to simulate head with sed 10q for a single
130 file, the standard developers decided that the popularity of head on
131 historical BSD systems warranted its inclusion alongside tail.
132
133 POSIX.1‐2008 version of head follows the Utility Syntax Guidelines. The
134 −n option was added to this new interface so that head and tail would
135 be more logically related. Earlier versions of this standard allowed a
136 −number option. This form is no longer specified by POSIX.1‐2008 but
137 may be present in some implementations.
138
139 There is no −c option (as there is in tail) because it is not histori‐
140 cal practice and because other utilities in this volume of POSIX.1‐2008
141 provide similar functionality.
142
144 None.
145
147 sed, tail
148
149 The Base Definitions volume of POSIX.1‐2008, Chapter 8, Environment
150 Variables, Section 12.2, Utility Syntax Guidelines
151
153 Portions of this text are reprinted and reproduced in electronic form
154 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
155 -- Portable Operating System Interface (POSIX), The Open Group Base
156 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
157 cal and Electronics Engineers, Inc and The Open Group. (This is
158 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
159 event of any discrepancy between this version and the original IEEE and
160 The Open Group Standard, the original IEEE and The Open Group Standard
161 is the referee document. The original Standard can be obtained online
162 at http://www.unix.org/online.html .
163
164 Any typographical or formatting errors that appear in this page are
165 most likely to have been introduced during the conversion of the source
166 files to man page format. To report such errors, see https://www.ker‐
167 nel.org/doc/man-pages/reporting_bugs.html .
168
169
170
171IEEE/The Open Group 2013 HEAD(1P)