Count things with wc
Count lines, words, and characters
⏱ Est. ~4 min
01 · Read
Sometimes you want to know how much is in a file: how many lines, words, or characters. wc counts for you.
💡 Picture thisLike the word-count tool in a text editor — but on the command line.
Key points
- wc is short for word count
- wc -l counts only lines
- Pairs great with pipes: cat file | wc -l counts a file's lines
02 · Terminal exercise
You've got a 100-line server log. But how do you know it's 100 without counting line by line? wc handles it.
(This section is interactive — please enable JavaScript.)
03 · Terminal exercise
How many errors are in the log? Combine grep and wc with a pipe.
(This section is interactive — please enable JavaScript.)
04 · Terminal exercise
Now count the warnings. Same trick: grep to filter, pipe into wc to count.
(This section is interactive — please enable JavaScript.)
05 · Fill in the blank
To count how many lines are in a file, pipe its contents into: ___ -l
Other lessons in this chapter
⚠ The full interactive experience needs JavaScript. Please enable it and reload.
※ This is an independent Traditional Chinese teaching project — not an official Anthropic product. Claude™ is a trademark of Anthropic, PBC.