xref: /openbsd-src/usr.bin/wc/wc.1 (revision e291b8af02e5c2b53d7ddb1f0c9c0fd608b97d45)
1.\"	$OpenBSD: wc.1,v 1.28 2024/09/11 03:57:14 guenther Exp $
2.\"
3.\" Copyright (c) 1991, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" the Institute of Electrical and Electronics Engineers, Inc.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. Neither the name of the University nor the names of its contributors
18.\"    may be used to endorse or promote products derived from this software
19.\"    without specific prior written permission.
20.\"
21.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31.\" SUCH DAMAGE.
32.\"
33.\"     from: @(#)wc.1	8.2 (Berkeley) 4/19/94
34.\"
35.Dd $Mdocdate: September 11 2024 $
36.Dt WC 1
37.Os
38.Sh NAME
39.Nm wc
40.Nd word, line, and byte or character count
41.Sh SYNOPSIS
42.Nm wc
43.Op Fl c | m
44.Op Fl hlw
45.Op Ar
46.Sh DESCRIPTION
47The
48.Nm
49utility reads one or more input text files and, by
50default, writes the number of lines, words, and bytes
51contained in each input file to the standard output.
52If more than one input file is specified,
53a line of cumulative count(s) for all named files is output on a
54separate line following the last file count.
55.Nm
56considers a word to be a maximal string of characters delimited by
57whitespace.
58Whitespace characters are the set of characters for which the
59.Xr isspace 3
60function returns true.
61.Pp
62The options are as follows:
63.Bl -tag -width Ds
64.It Fl c
65The number of bytes in each input file
66is written to the standard output.
67.It Fl h
68Use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte,
69Petabyte, and Exabyte in order to reduce the number of digits to four or fewer
70using powers of 2 for sizes (K=1024, M=1048576, etc.).
71.It Fl l
72The number of lines in each input file
73is written to the standard output.
74.It Fl m
75Count characters instead of bytes, and use
76.Xr iswspace 3
77instead of
78.Xr isspace 3 .
79.It Fl w
80The number of words in each input file
81is written to the standard output.
82.El
83.Pp
84When an option is specified,
85.Nm
86only reports the information requested by that option.
87The default action is equivalent to the flags
88.Fl clw
89having been specified.
90.Pp
91If no file names are specified, the standard input is used
92and a file name is not output.
93The resulting output is one
94line of the requested count(s) with the cumulative sum
95of all files read in via standard input.
96.Pp
97By default, the standard output contains a line for each
98input file of the form:
99.Bd -literal -offset indent
100lines	 words	bytes	file_name
101.Ed
102.Pp
103The counts for lines, words, and bytes
104.Pq or characters
105are integers separated by spaces.
106.Sh ENVIRONMENT
107.Bl -tag -width LC_CTYPE
108.It Ev LC_CTYPE
109The character encoding
110.Xr locale 1 .
111It decides which byte sequences form characters.
112If unset or set to
113.Qq C ,
114.Qq POSIX ,
115or an unsupported value,
116.Fl m
117has the same effect as
118.Fl c .
119.El
120.Sh EXIT STATUS
121.Ex -std wc
122.Sh SEE ALSO
123.Xr isspace 3
124.Sh STANDARDS
125The
126.Nm
127utility is compliant with the
128.St -p1003.1-2024
129specification.
130.Pp
131The flag
132.Op Fl h
133is an extension to that specification.
134.Sh HISTORY
135A
136.Nm
137utility appeared in
138.At v1 .
139