| wc | |
|---|---|
The wc command | |
| Original authors | Joe Ossanna (AT&T Bell Laboratories) |
| Developers | Variousopen-source andcommercial developers |
| Initial release | November 3, 1971; 54 years ago (1971-11-03) |
| Written in | C |
| Operating system | Unix,Unix-like,V,Plan 9,Inferno,MSX-DOS,IBM i |
| Platform | Cross-platform |
| Type | Command |
| License | Plan 9, Inferno:MIT coreutils:GPL-3.0-or-later |
wc (short forwordcount) is a command inUnix,Plan 9,Inferno, andoperating systems that areUnix-like. The program reads eitherstandard input or a list ofcomputer files and generates one or more of the following statistics:newline count,word count, andbyte count. If a list of files is provided, both individual file and total statistics follow.
Sample execution ofwc:
$wcfoobar 40 149 947 foo 2294 16638 97724 bar 2334 16787 98671 total
The first column is the count of newlines, meaning that the text filefoo has 40 newlines whilebar 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 infoo and 16638 words inbar – giving a total of 16787 words. The last column indicates the number of characters in each text file, meaning that the filefoo has 947 characters whilebar has 97724 characters – 98671 characters all in all.
Newer versions ofwc can differentiate betweenbyte andcharacter count. This difference arises withUnicode which includes multi-byte characters. The desired behaviour is selected with the-c or-m options.
Through apipeline, 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:
$grep-r"example"|wc 1071 23337 101349
wc is part of theX/Open Portability Guide since issue 2 of 1987. It was inherited into the first version ofPOSIX.1 and theSingle Unix Specification.[1] It appeared inVersion 1 Unix.[2]
GNUwc used to be part of the GNUtextutils package; it is now part of GNUcoreutils. The version ofwc bundled in GNU coreutils was written by Paul Rubin and David MacKenzie.[3]
Awc command is also part ofASCII'sMSX-DOS2 Tools forMSX-DOS version 2.[4]
The command is available as a separate package forMicrosoft Windows as part of theGnuWin32 project[5] and theUnxUtils collection ofnativeWin32ports of common GNU Unix-like utilities.[6]
Thewc command has also been ported to theIBM i operating system.[7]
wc -c <filename> prints the byte countwc -l <filename> prints the line countwc -m <filename> prints the character countwc -w <filename> prints the word countwc -L <filename> prints the length of the longest line (GNU extension)wc – Shell and Utilities Reference,The Single UNIX Specification, Version 5 fromThe Open Groupwc(1) – FreeBSD General CommandsManualwc(1) – Linux User CommandsManualwc(1) – Plan 9 Programmer's Manual, Volume 1wc(1) – Inferno General commandsManualwc Command by The Linux Information Project (LINFO)