WC(1P)
π PROLOG π
okay so bestie, before literally anything else: this manual page is part of the POSIX Programmer's Manual (yes, the whole thing, it's giving official π). But heads up β the Linux implementation of this interface may differ, so like, consult the corresponding Linux manual page for the deets on Linux behavior. Or it might not even be implemented on Linux at all π. vibes vary, check your local setup.
β¨ NAME β¨
wc β word, line, and byte or character count π
πΈ SYNOPSIS πΈ
wc [-c|-m] [-lw] [file...]
π¦ DESCRIPTION π¦
so the wc utility shall read one or more input files and, by default, write the number of <newline> characters, words, and bytes contained in each input file to the standard output. three numbers, one slay π
The utility also shall write a total count for all named files, if more than one input file is specified. like a lil sum-up at the end, bestie, iconic behavior.
And the way wc defines a word? a word is a non-zero-length string of characters delimited by white space. that's the whole definition. no notes. periodt.
π OPTIONS π
The wc utility shall conform to the Base Definitions volume of POSIX.1β2017, Section 12.2, Utility Syntax Guidelines. (yes bestie, the rules of the game.)
The following options shall be supported:
-cβ write to the standard output the number of bytes in each input file. bytes only. raw. β¨-lβ write to the standard output the number of<newline>characters in each input file. line vibes.-mβ write to the standard output the number of characters in each input file. not bytes!! characters!! (more on this drama in RATIONALE, iykyk)-wβ write to the standard output the number of words in each input file.
When any option is specified, wc shall report only the information requested by the specified options. like, don't give us extra, we asked for one thing π
π OPERANDS π
The following operand shall be supported:
fileβ a pathname of an input file. If no file operands are specified, the standard input shall be used. (so like, if you give it nothing, it just reads whatever you pipe in π«Ά)
π STDIN π
The standard input shall be used if no file operands are specified, and shall be used if a file operand is '-' and the implementation treats the '-' as meaning standard input. Otherwise, the standard input shall not be used. See the INPUT FILES section. no cap, it's in the INPUT FILES section, go look.
β INPUT FILES β
The input files may be of any type. any. type. literally anything bestie, wc is not picky π
πΈ ENVIRONMENT VARIABLES πΈ
The following environment variables shall affect the execution of wc:
LANGβ provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of POSIX.1β2017, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.)LC_ALLβ if set to a non-empty string value, override the values of all the other internationalization variables. it's the main character, it overrides everyone π€LC_CTYPEβ determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments and input files) and which characters are defined as white-space characters. this one decides what even counts as a space, so it's lowkey important.LC_MESSAGESβ determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informative messages written to standard output.NLSPATHβ determine the location of message catalogs for the processing ofLC_MESSAGES.
π« ASYNCHRONOUS EVENTS π«
Default. that's it. that's the section. π
π STDOUT π
By default, the standard output shall contain an entry for each input file of the form:
"%d %d %d %s\n", <newlines>, <words>, <bytes>, <file>
If the -m option is specified, the number of characters shall replace the <bytes> field in this format.
If any options are specified and the -l option is not specified, the number of <newline> characters shall not be written.
If any options are specified and the -w option is not specified, the number of words shall not be written.
If any options are specified and neither -c nor -m is specified, the number of bytes or characters shall not be written.
If no input file operands are specified, no name shall be written and no <blank> characters preceding the pathname shall be written. (so it's just numbers, no trailing space situation, we're clean here π§Ό)
If more than one input file operand is specified, an additional line shall be written, of the same format as the other lines, except that the word total (in the POSIX locale) shall be written instead of a pathname and the total of each column shall be written as appropriate. Such an additional line, if any, is written at the end of the output. that's your lil recap bestie π«Ά
π©· STDERR π©·
The standard error shall be used only for diagnostic messages. nothing else. don't put your whole personality in stderr.
π OUTPUT FILES π
None. (nope. nada. zero. π)
π§ EXTENDED DESCRIPTION π§
None. (again, nothing!! it's a chill utility!!)
π₯ EXIT STATUS π₯
The following exit values shall be returned:
0β successful completion. slay β¨>0β an error occurred. π
π CONSEQUENCES OF ERRORS π
Default.
The following sections are informative. (aka the tea, the lore, the backstory β none of it is normative, it's just for the girlies who want context π )
π«Ά APPLICATION USAGE π«Ά
okay this one is actually important so pay attention bestie:
The -m option is not a switch, but an option at the same level as -c. Thus, to produce the full default output with character counts instead of bytes, the command required is:
wc -mlw
not wc -lwm-adjacent switch magic, just. options. at the same level. periodt.
π EXAMPLES π
None. (no examples, bestie, we're keeping it mysterious πΈ)
π RATIONALE π
okay this is the lore section, grab a snack π
The output file format pseudo-printf() string differs from the System V version of wc:
"%7d%7d%7d %s\n"
which produces possibly ambiguous and unparsable results for very large files, as it assumes no number shall exceed six digits. (imagine assuming that. couldn't be POSIX. π )
Some historical implementations use only <space>, <tab>, and <newline> as word separators. The equivalent of the ISO C standard isspace() function is more appropriate.
The -c option stands for character'' count, even though it counts bytes. This stems from the sometimes erroneous historical view that bytes and characters are the same size. Due to international requirements, the `-m` option (reminiscent of multi-byte'') was added to obtain actual character counts. so -c is lying a lil bit and -m is the honest one, that's the drama π«
Early proposals only specified the results when input files were text files. The current specification more closely matches historical practice. (Bytes, words, and <newline> characters are counted separately and the results are written when an end-of-file is detected.)
Historical implementations of the wc utility only accepted one argument to specify the options -c, -l, and -w. Some of them also had multiple occurrences of an option cause the corresponding count to be written multiple times and had the order of specification of the options affect the order of the fields on output, but did not document either of these. Because common usage either specifies no options or only one option, and because none of this was documented, the changes required by this volume of POSIX.1β2017 should not break many historical applications (and do not break any historical conforming applications). messy undocumented behavior? we don't know her anymore β¨
π FUTURE DIRECTIONS π
None. (the future is empty, bestie. just vibes. π¦)
β SEE ALSO β
cksum- The Base Definitions volume of POSIX.1β2017, Chapter 8, Environment Variables, Section 12.2, Utility Syntax Guidelines
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page bestie, no cap π«Ά this was IEEE/The Open Group, 2017, WC(1P) β she's old, she's iconic, she counts words, she ate and left no crumbs ππ
β¨
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms