1WC(1P)                     POSIX Programmer's Manual                    WC(1P)
2
3
4

PROLOG

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

NAME

12       wc — word, line, and byte or character count
13

SYNOPSIS

15       wc [-c|-m] [-lw] [file...]
16

DESCRIPTION

18       The wc utility shall read one or more  input  files  and,  by  default,
19       write the number of <newline> characters, words, and bytes contained in
20       each input file to the standard output.
21
22       The utility also shall write a total count for all named files, if more
23       than one input file is specified.
24
25       The  wc utility shall consider a word to be a non-zero-length string of
26       characters delimited by white space.
27

OPTIONS

29       The wc  utility  shall  conform  to  the  Base  Definitions  volume  of
30       POSIX.1‐2017, Section 12.2, Utility Syntax Guidelines.
31
32       The following options shall be supported:
33
34       -c        Write  to  the  standard  output  the number of bytes in each
35                 input file.
36
37       -l        Write to the standard output the number of <newline>  charac‐
38                 ters in each input file.
39
40       -m        Write to the standard output the number of characters in each
41                 input file.
42
43       -w        Write to the standard output the  number  of  words  in  each
44                 input file.
45
46       When  any  option  is  specified,  wc shall report only the information
47       requested by the specified options.
48

OPERANDS

50       The following operand shall be supported:
51
52       file      A pathname of an input file. If no file operands  are  speci‐
53                 fied, the standard input shall be used.
54

STDIN

56       The standard input shall be used if no file operands are specified, and
57       shall be used if a file operand is '-' and  the  implementation  treats
58       the '-' as meaning standard input.  Otherwise, the standard input shall
59       not be used.  See the INPUT FILES section.
60

INPUT FILES

62       The input files may be of any type.
63

ENVIRONMENT VARIABLES

65       The following environment variables shall affect the execution of wc:
66
67       LANG      Provide a default value for  the  internationalization  vari‐
68                 ables  that are unset or null. (See the Base Definitions vol‐
69                 ume of POSIX.1‐2017, Section 8.2, Internationalization  Vari‐
70                 ables  for  the  precedence of internationalization variables
71                 used to determine the values of locale categories.)
72
73       LC_ALL    If set to a non-empty string value, override  the  values  of
74                 all the other internationalization variables.
75
76       LC_CTYPE  Determine  the  locale for the interpretation of sequences of
77                 bytes of text data as characters (for example, single-byte as
78                 opposed  to  multi-byte  characters  in  arguments  and input
79                 files) and which characters are defined as white-space  char‐
80                 acters.
81
82       LC_MESSAGES
83                 Determine the locale that should be used to affect the format
84                 and contents of diagnostic messages written to standard error
85                 and informative messages written to standard output.
86
87       NLSPATH   Determine the location of message catalogs for the processing
88                 of LC_MESSAGES.
89

ASYNCHRONOUS EVENTS

91       Default.
92

STDOUT

94       By default, the standard output shall contain an entry for  each  input
95       file of the form:
96
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

STDERR

122       The standard error shall be used only for diagnostic messages.
123

OUTPUT FILES

125       None.
126

EXTENDED DESCRIPTION

128       None.
129

EXIT STATUS

131       The following exit values shall be returned:
132
133        0    Successful completion.
134
135       >0    An error occurred.
136

CONSEQUENCES OF ERRORS

138       Default.
139
140       The following sections are informative.
141

APPLICATION USAGE

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
148           wc -mlw
149

EXAMPLES

151       None.
152

RATIONALE

154       The output file format pseudo-printf() string differs from the System V
155       version of wc:
156
157
158           "%7d%7d%7d %s\n"
159
160       which produces possibly ambiguous and unparsable results for very large
161       files, as it assumes no number shall exceed six digits.
162
163       Some historical implementations use only <space>, <tab>, and  <newline>
164       as  word  separators.  The  equivalent  of the ISO C standard isspace()
165       function is more appropriate.
166
167       The -c option stands for ``character'' count,  even  though  it  counts
168       bytes.   This  stems  from the sometimes erroneous historical view that
169       bytes and characters are the same size. Due to  international  require‐
170       ments,  the  -m  option  (reminiscent  of  ``multi-byte'') was added to
171       obtain actual character counts.
172
173       Early proposals only specified the results when input files  were  text
174       files.  The current specification more closely matches historical prac‐
175       tice. (Bytes, words, and <newline> characters  are  counted  separately
176       and the results are written when an end-of-file is detected.)
177
178       Historical implementations of the wc utility only accepted one argument
179       to specify the options -c, -l, and -w.  Some of them also had  multiple
180       occurrences  of  an  option cause the corresponding count to be written
181       multiple times and had the order of specification of the options affect
182       the  order  of  the  fields  on  output, but did not document either of
183       these. Because common usage either specifies no  options  or  only  one
184       option,  and  because none of this was documented, the changes required
185       by this volume of POSIX.1‐2017 should not break many historical  appli‐
186       cations (and do not break any historical conforming applications).
187

FUTURE DIRECTIONS

189       None.
190

SEE ALSO

192       cksum
193
194       The  Base  Definitions  volume  of POSIX.1‐2017, Chapter 8, Environment
195       Variables, Section 12.2, Utility Syntax Guidelines
196
198       Portions of this text are reprinted and reproduced in  electronic  form
199       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
200       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
201       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
202       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
203       event of any discrepancy between this version and the original IEEE and
204       The Open Group Standard, the original IEEE and The Open Group  Standard
205       is  the  referee document. The original Standard can be obtained online
206       at http://www.opengroup.org/unix/online.html .
207
208       Any typographical or formatting errors that appear  in  this  page  are
209       most likely to have been introduced during the conversion of the source
210       files to man page format. To report such errors,  see  https://www.ker
211       nel.org/doc/man-pages/reporting_bugs.html .
212
213
214
215IEEE/The Open Group                  2017                               WC(1P)
Impressum