xref: /src/usr.bin/wc/wc.1 (revision 4cb65fde79a2412558d10fdbf3427fc0e4536d80)
1.\"
2.\" SPDX-License-Identifier: BSD-3-Clause
3.\"
4.\" Copyright (c) 1991, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" This code is derived from software contributed to Berkeley by
8.\" the Institute of Electrical and Electronics Engineers, Inc.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in the
17.\"    documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd July 16, 2025
35.Dt WC 1
36.Os
37.Sh NAME
38.Nm wc
39.Nd word, line, character, and byte count
40.Sh SYNOPSIS
41.Nm
42.Op Fl -libxo
43.Op Fl c | Fl m
44.Op Fl Llw
45.Op Ar
46.Sh DESCRIPTION
47The
48.Nm
49utility displays the number of lines, words, and bytes contained in each
50input
51.Ar file ,
52or standard input (if no file is specified) to the standard output.
53A line is defined as a string of characters delimited by a
54.Dq newline
55character.
56Characters beyond the final
57.Dq newline
58character will not be included
59in the line count.
60.Pp
61A word is defined as a string of characters delimited by white space
62characters.
63White space characters are the set of characters for which the
64.Xr iswspace 3
65function returns true.
66If more than one input file is specified, a line of cumulative counts
67for all the files is displayed on a separate line after the output for
68the last file.
69.Pp
70The following options are available:
71.Bl -tag -width "--libxo"
72.It Fl -libxo
73Generate output via
74.Xr libxo 3
75in a selection of different human and machine readable formats.
76See
77.Xr xo_options 7
78for details on command line arguments.
79.It Fl L
80Write the length of the line containing the most bytes (default) or characters
81(when
82.Fl m
83is provided)
84to standard output.
85When more than one
86.Ar file
87argument is specified, the longest input line of
88.Em all
89files is reported as the value of the final
90.Dq total .
91.It Fl c
92The number of bytes in each input file
93is written to the standard output.
94This will cancel out any prior usage of the
95.Fl m
96option.
97.It Fl l
98The number of lines in each input file
99is written to the standard output.
100.It Fl m
101The number of characters in each input file is written to the standard output.
102If the current locale does not support multibyte characters, this
103is equivalent to the
104.Fl c
105option.
106This will cancel out any prior usage of the
107.Fl c
108option.
109.It Fl w
110The number of words in each input file
111is written to the standard output.
112.El
113.Pp
114When an option is specified,
115.Nm
116only reports the information requested by that option.
117The order of output always takes the form of line, word,
118byte, and file name.
119The default action is equivalent to specifying the
120.Fl c , l
121and
122.Fl w
123options.
124.Pp
125If no files are specified, the standard input is used and no
126file name is displayed.
127The prompt will accept input until receiving EOF, or
128.Bq ^D
129in most environments.
130.Pp
131If
132.Nm
133receives a
134.Dv SIGINFO
135(see the
136.Cm status
137argument for
138.Xr stty 1 )
139signal, the interim data will be written
140to the standard error output in the same format
141as the standard completion message.
142.Sh ENVIRONMENT
143The
144.Ev LANG , LC_ALL
145and
146.Ev LC_CTYPE
147environment variables affect the execution of
148.Nm
149as described in
150.Xr environ 7 .
151.Sh EXIT STATUS
152.Ex -std
153.Sh EXAMPLES
154Count the number of characters, words and lines in each of the files
155.Pa report1
156and
157.Pa report2
158as well as the totals for both:
159.Pp
160.Dl "wc -mlw report1 report2"
161.Pp
162Find the longest line in a list of files:
163.Pp
164.Dl "wc -L file1 file2 file3 | fgrep total"
165.Sh COMPATIBILITY
166Historically, the
167.Nm
168utility was documented to define a word as a
169.Do
170maximal string of
171characters delimited by <space>, <tab> or <newline> characters
172.Dc .
173The implementation, however, did not handle non-printing characters
174correctly so that
175.Dq Li "\ \ ^D^E\ \ "
176counted as 6 spaces, while
177.Dq Li foo^D^Ebar
178counted as 8 characters.
179.Bx 4
180systems after
181.Bx 4.3
182modified the implementation to be consistent
183with the documentation.
184This implementation defines a
185.Dq word
186in terms of the
187.Xr iswspace 3
188function, as required by
189.St -p1003.2 .
190.Pp
191The
192.Fl L
193option is a non-standard
194.Fx
195extension, compatible with the
196.Fl L
197option of the GNU
198.Nm
199utility.
200.Sh SEE ALSO
201.Xr iswspace 3 ,
202.Xr libxo 3 ,
203.Xr xo_options 7
204.Sh STANDARDS
205The
206.Nm
207utility conforms to
208.St -p1003.1-2001 .
209.Sh HISTORY
210A
211.Nm
212command appeared in
213.At v1 .
214