How to use the linux wc command
The Linux wc command (word count) quickly reports how many lines, words, and bytes a file contains. It is simple, fast, and especially useful in scripts and pipelines when you need to count something. In this article, we will show you the basic usage of the Linux wc command with examples.
Basic wc usage
First, run wc with a filename. It prints three numbers – lines, words, and bytes – followed by the filename:
wc myFile.txt
# => 12 84 560 myFile.txtCount lines, words, or characters
Next, add a flag to show just one figure. This keeps output clean when you only need a single number:
wc -l– count lines.wc -w– count words.wc -c– count bytes.wc -m– count characters.
wc -l access.log
# => 1543 access.logCount across several files
Additionally, you can pass several files or a wildcard. The wc command lists each file and adds a total line at the end:
wc -l *.txtUse wc in a pipeline
Finally, wc is at its best when it counts the output of another command. For example, count how many processes match a name, or how many files are in a folder:
ls | wc -l
grep "error" app.log | wc -lWhen you pipe input into it, the Linux wc command counts that stream instead of a file, so the filename is omitted from the output. This is why ls | wc -l gives you a plain count of items in the current directory. A quick tip: -c counts bytes while -m counts characters, and the two differ for files that use multi-byte encodings such as UTF-8. Because wc only reads data, it is completely safe to run at any time, making it a handy building block in your everyday commands.
Need more help?
Explore more Linux commands with examples on an SSH shared hosting account, or get full root control with a JetHost VPS.


