Tuesday, May 12, 2009

wc

The wc program on *nix boxes is used to count words, lines, characters, or bytes. Like most *nix programs, wc by default reads from standard input. This allows one to pipe the output of another program into the input of wc (this is a standard idiom with command line programs on *nix). I made use of this recently to count the number of files in the current directory:
ls | wc -l
The ls prints a list of files to standard output. This output is piped to the standard input of the wc program. The wc program is invoked with the -l (that is, dash ell) option which requests a line count.

No comments: