(short for word count) is a command in Unix, Plan 9, Inferno, and operating systems that are Unix-like. The program reads either standard input or a list of computer files and generates one or more of the following statistics: newline count, word count, and byte count. If a list of files is provided, both individual file and total statistics follow.
Example
Sample execution of wc:
<syntaxhighlight lang="console">
$ wc foo bar
40 149 947 foo
2294 16638 97724 bar
2334 16787 98671 total
</syntaxhighlight>
The first column is the count of newlines, meaning that the text file <code>foo</code> has 40 newlines while <code>bar</code> has 2294 newlines- resulting in a total of 2334 newlines. The second column indicates the number of words in each text file showing that there are 149 words in <code>foo</code> and 16638 words in <code>bar</code> giving a total of 16787 words. The last column indicates the number of characters in each text file, meaning that the file <code>foo</code> has 947 characters while <code>bar</code> has 97724 characters 98671 characters all in all.
Newer versions of <code>wc</code> can differentiate between byte and character count. This difference arises with Unicode which includes multi-byte characters. The desired behaviour is selected with the <code>-c</code> or <code>-m</code> options.
Through a pipeline, it can also be used to preview the output size of a command with a potentially large output, without it printing the text into the console:
<syntaxhighlight lang="console">
$ grep -r "example" | wc
1071 23337 101349
</syntaxhighlight>
History
is part of the X/Open Portability Guide since issue 2 of 1987. It was inherited into the first version of POSIX.1 and the Single Unix Specification. It appeared in Version 1 Unix.
GNU <code>wc</code> used to be part of the GNU textutils package; it is now part of GNU coreutils. The version of <code>wc</code> bundled in GNU coreutils was written by Paul Rubin and David MacKenzie.
A <code>wc</code> command is also part of ASCII's MSX-DOS2 Tools for MSX-DOS version 2.
The command is available as a separate package for Microsoft Windows as part of the GnuWin32 project and the UnxUtils collection of native Win32 ports of common GNU Unix-like utilities.
The command has also been ported to the IBM i operating system.
Usage
- <code>wc -c <filename></code> prints the byte count
- <code>wc -l <filename></code> prints the line count
- <code>wc -m <filename></code> prints the character count
- <code>wc -w <filename></code> prints the word count
- <code>wc -L <filename></code> prints the length of the longest line (GNU extension)
See also
- List of Unix commands
References
External links
- wc(1) - Original Unix First Edition manual page for wc.
- The <code>wc</code> Command by The Linux Information Project (LINFO)
