How to Use the wc Command in Linux
The wc command is a small application. It’s one of the core Linux utilities, so there is no need to install it. It’ll already be on your Linux computer. You can describe what it does in a very few words. It counts the lines, words, and bytes in a file or selection of files and prints the result in a terminal window. It can also take its input from the STDIN stream, meaning the text you want it to process can be piped into it. This is where wc really starts to add value.
It is a great example of the Linux mantra of “do one thing and do it well.” Because it accepts piped input, it can be used in multi-command incantations. As we’ll see, this little standalone utility is actually a great team player.
One way I use wc is as a placeholder in a complicated command or alias I’m cooking up. If the finished command has the potential to be destructive and delete files, I often use wc as a stand-in for the real, dangerous command. That way, during the development of the command I get visual feedback that each file is being processed as I expected. There’s no chance of anything bad happening while I’m wrestling with the syntax.
As simple as wc is, there are still a few small quirks that you need to know about.