Ad space (banner)
🖥️Linux Lessons
Lesson 18 / 61

Counting Lines & Characters with wc

wc is for when "I want to count how many lines or characters are in this file." wc stands for word count, and it counts a file's lines, words, and bytes.

Use it in the form wc filename. Add -l for just the line count, -w for just the word count, or -c for just the byte count.

Running wc notes.txt displays the line count, word count, and byte count for notes.txt, all together on one line.

A common early mistake is not accounting for multi-byte characters in non-English text, so -c's result looks larger than expected — since some characters take up more than one byte.

In real work, combining it with a pipe like grep | wc -l to quickly count how many lines match a condition is a very common technique.

Linux
Try it (type this into the pseudo terminal)
wc notes.txt

🧑‍💻 You can type this command into the Linux pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)