Closed Captioning Closed captioning available on our YouTube channel

How to use the wc command: 2-Minute Linux Tips

Network World | Aug 16, 2019

Learn the wc command. It provides an easy way to count the lines, words and characters in a file or in output from some other command.

Similar
Hi, this is Sandra Henry-Stocker, author of the “Unix as a Second Language” blog on NetworkWorld.
In this Linux tip, we’re going to look at the wc command. It provides an easy way to count the lines, words and characters in a file or in output from some other command.
The easiest way to see how it works is to send some output on the command like this:
The numbers shown report on 1) the number of lines in the text, 2) the number of words and 3) the number of characters. Notice anything odd? Well, yes, “123” is only three characters long. The wc command is also counting the newline that echo adds to the end of its output. If you use echo -n instead (suppressing the newline), you’ll see this:
You can get these same stats on a file by providing the file name:
That’s 6 lines, 71 words and 392 characters (including newlines).
You can also tell wc that you only want to see one or these three stats. For example, if you only want to know how many lines are in a file, you can do this:
If you only want to know how many words are in a file, you can do this:
Any time you need to know how many lines or words are in a file, wc is an easy way to get those stats.
That’s your Linux tip for the wc command.
If you have questions or would like to suggest a topic, please add a comment below.
And don’t forget to subscribe to the IDG Tech(talk) channel on YouTube.
If you liked this video, please hit the like and share buttons. For more Linux tips, be sure to follow us on Facebook, YouTube and NetworkWorld.com.
Featured videos from IDG.tv