1WC(1P) POSIX Programmer's Manual WC(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 wc — word, line, and byte or character count
14
16 wc [−c|−m] [−lw] [file...]
17
19 The wc utility shall read one or more input files and, by default,
20 write the number of <newline> characters, words, and bytes contained in
21 each input file to the standard output.
22
23 The utility also shall write a total count for all named files, if more
24 than one input file is specified.
25
26 The wc utility shall consider a word to be a non-zero-length string of
27 characters delimited by white space.
28
30 The wc utility shall conform to the Base Definitions volume of
31 POSIX.1‐2008, Section 12.2, Utility Syntax Guidelines.
32
33 The following options shall be supported:
34
35 −c Write to the standard output the number of bytes in each
36 input file.
37
38 −l Write to the standard output the number of <newline> charac‐
39 ters in each input file.
40
41 −m Write to the standard output the number of characters in each
42 input file.
43
44 −w Write to the standard output the number of words in each
45 input file.
46
47 When any option is specified, wc shall report only the information
48 requested by the specified options.
49
51 The following operand shall be supported:
52
53 file A pathname of an input file. If no file operands are speci‐
54 fied, the standard input shall be used.
55
57 The standard input shall be used if no file operands are specified, and
58 shall be used if a file operand is '−' and the implementation treats
59 the '−' as meaning standard input. Otherwise, the standard input shall
60 not be used. See the INPUT FILES section.
61
63 The input files may be of any type.
64
66 The following environment variables shall affect the execution of wc:
67
68 LANG Provide a default value for the internationalization vari‐
69 ables that are unset or null. (See the Base Definitions vol‐
70 ume of POSIX.1‐2008, Section 8.2, Internationalization Vari‐
71 ables for the precedence of internationalization variables
72 used to determine the values of locale categories.)
73
74 LC_ALL If set to a non-empty string value, override the values of
75 all the other internationalization variables.
76
77 LC_CTYPE Determine the locale for the interpretation of sequences of
78 bytes of text data as characters (for example, single-byte as
79 opposed to multi-byte characters in arguments and input
80 files) and which characters are defined as white-space char‐
81 acters.
82
83 LC_MESSAGES
84 Determine the locale that should be used to affect the format
85 and contents of diagnostic messages written to standard error
86 and informative messages written to standard output.
87
88 NLSPATH Determine the location of message catalogs for the processing
89 of LC_MESSAGES.
90
92 Default.
93
95 By default, the standard output shall contain an entry for each input
96 file of the form:
97
98 "%d %d %d %s\n", <newlines>, <words>, <bytes>, <file>
99
100 If the −m option is specified, the number of characters shall replace
101 the <bytes> field in this format.
102
103 If any options are specified and the −l option is not specified, the
104 number of <newline> characters shall not be written.
105
106 If any options are specified and the −w option is not specified, the
107 number of words shall not be written.
108
109 If any options are specified and neither −c nor −m is specified, the
110 number of bytes or characters shall not be written.
111
112 If no input file operands are specified, no name shall be written and
113 no <blank> characters preceding the pathname shall be written.
114
115 If more than one input file operand is specified, an additional line
116 shall be written, of the same format as the other lines, except that
117 the word total (in the POSIX locale) shall be written instead of a
118 pathname and the total of each column shall be written as appropriate.
119 Such an additional line, if any, is written at the end of the output.
120
122 The standard error shall be used only for diagnostic messages.
123
125 None.
126
128 None.
129
131 The following exit values shall be returned:
132
133 0 Successful completion.
134
135 >0 An error occurred.
136
138 Default.
139
140 The following sections are informative.
141
143 The −m option is not a switch, but an option at the same level as −c.
144 Thus, to produce the full default output with character counts instead
145 of bytes, the command required is:
146
147 wc −mlw
148
150 None.
151
153 The output file format pseudo-printf() string differs from the System V
154 version of wc:
155
156 "%7d%7d%7d %s\n"
157
158 which produces possibly ambiguous and unparsable results for very large
159 files, as it assumes no number shall exceed six digits.
160
161 Some historical implementations use only <space>, <tab>, and <newline>
162 as word separators. The equivalent of the ISO C standard isspace()
163 function is more appropriate.
164
165 The −c option stands for ``character'' count, even though it counts
166 bytes. This stems from the sometimes erroneous historical view that
167 bytes and characters are the same size. Due to international require‐
168 ments, the −m option (reminiscent of ``multi-byte'') was added to
169 obtain actual character counts.
170
171 Early proposals only specified the results when input files were text
172 files. The current specification more closely matches historical prac‐
173 tice. (Bytes, words, and <newline> characters are counted separately
174 and the results are written when an end-of-file is detected.)
175
176 Historical implementations of the wc utility only accepted one argument
177 to specify the options −c, −l, and −w. Some of them also had multiple
178 occurrences of an option cause the corresponding count to be written
179 multiple times and had the order of specification of the options affect
180 the order of the fields on output, but did not document either of
181 these. Because common usage either specifies no options or only one
182 option, and because none of this was documented, the changes required
183 by this volume of POSIX.1‐2008 should not break many historical appli‐
184 cations (and do not break any historical conforming applications).
185
187 None.
188
190 cksum
191
192 The Base Definitions volume of POSIX.1‐2008, Chapter 8, Environment
193 Variables, Section 12.2, Utility Syntax Guidelines
194
196 Portions of this text are reprinted and reproduced in electronic form
197 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
198 -- Portable Operating System Interface (POSIX), The Open Group Base
199 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
200 cal and Electronics Engineers, Inc and The Open Group. (This is
201 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
202 event of any discrepancy between this version and the original IEEE and
203 The Open Group Standard, the original IEEE and The Open Group Standard
204 is the referee document. The original Standard can be obtained online
205 at http://www.unix.org/online.html .
206
207 Any typographical or formatting errors that appear in this page are
208 most likely to have been introduced during the conversion of the source
209 files to man page format. To report such errors, see https://www.ker‐
210 nel.org/doc/man-pages/reporting_bugs.html .
211
212
213
214IEEE/The Open Group 2013 WC(1P)