How to Count Lines, Words, and Characters in Linux (wc)

wc (word count) counts the number of lines, words, and characters (or bytes) in a file or piped input.

Published October 2, 2026

wc counts lines, words and bytes in files or piped input. wc -l is the quick way to count lines.

How it works

Flags: -l lines, -w words, -c bytes, -m characters. Without flags it prints lines, words and bytes.

Commonly used at the end of a pipeline to count results.

Try it

wc -l access.log
12843 access.log
grep 404 access.log | wc -l
57

Practical examples

Lines in a file

wc -l file.txt

Count matches

grep -c ERROR app.log

Lines of code

find src -name '*.js' | xargs wc -l

Characters vs bytes

echo 'é' | wc -m -c

Common mistakes

  • Counting lines in files without trailing newlines (off by one).
  • Using wc -c for characters in UTF-8.
  • Parsing wc output formats across platforms.

Key takeaways

  • wc -l counts lines.
  • -m chars, -c bytes.
  • Great at pipe ends.

FAQ

Why is my count one short?

The last line has no trailing newline.

Count files in a folder?

ls | wc -l or find . -type f | wc -l.

More Linux articles