NOTE: this website is out of date. This is the course web site from a past quarter. If you are a current student taking the course, you should visit the current class web site instead. If the current quarter's website is easily reached, it may be accessible by visiting this link instead. Please be advised that courses' policies change with each new quarter and instructor, and any information on this out-of-date page may not apply to you.
Written by Chris Gregg, with modifications by Nick Troccoli
Click here for a walkthrough video.
The wc ("word count") command counts the lines, words, and characters in a file:
$ wc hello.c
7 10 98 hello.c
$ cat hello.c
#include<stdio.h>
#include<stdlib.h>
int main() {
printf("Hello, World!\n");
return 0;
}
The hello.c file above has 7 lines, 10 words, and 98 characters.
The wc command can be useful if you need to count any output of a file, and it is frequently used by piping the output from a command or program:
$ ls -1 | wc
7 7 71
$
There are 7 files in the directory above.