The wc Command


The wc Command

In sum, the wc command counts words and provides you with a summary of what is found. Unix will report to you how many words are in a particular file. The wc stands for word count. When you want to see how many words are typed in a file, you simply need to execute the command and then the filename with its absolute or relative path. You will be shown the word count as well as the number of bytes, words, and lines in files.

The wc command is an excellent way to provide current statistics on a file you may want to work with. For example, if you wanted to issue the tail command on a file you think may be very large, you can use the wc command on a file to quickly see how many lines are in it. You can then use the tail command to jump the last grouping of text in the file you specify by line.

To use wc, simply supply the name of a file you want analyzed in the following form: wc <filename>. If you pass more than one filename to wc, all the files are processed, and a grand total for everything is returned. In the following example, we can see a simple query of a boot logfile that tells us what is picked up during Unix's inspection of the boot sequence when booting up.

 >wc /var/log/boot.msg 340 225 20102 /var/log/boot.msg 

This helps because I can see that the boot file is large and as I only wanted to see the end of it, I can now jump to the end using the tail command.

To read the command, you have to know what you are looking at. In this example, we saw a set of values returned by Unix when queried with the wc command. We see that the first value is 340. This is the number of lines in the file. The boot message file contains 340 lines. The second line is a count of the words in the file, and the third is the number of characters. The filename is just duplicated on the end of the line.

Is That a 250-Page Printout? Tree Killer In Lesson 17, "Printing with Unix," we will cover printing in detail. For now, you can use the wc command to see how large your print jobs are.


Now that we have learned about the wc command and how you can use it, what else is there to know? As mentioned earlier, this book is only large enough to skim the surface of what you can do. If you want to limit the values to lines, words, or characters, you can use the -l, -w, or -c options, respectively.



    SAMS Teach Yourself Unix in 10 Minutes
    Sams Teach Yourself Unix in 10 Minutes (2nd Edition)
    ISBN: 0672327643
    EAN: 2147483647
    Year: 2005
    Pages: 170

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net