Count with wc

Device

  • Terminal

How

  1. Use wc -l to count lines.
  2. ls | wc -l gives an approximate count of visible listing lines (not a robust count of all files).
  3. grep "pattern" file.txt | wc -l counts matching lines.
  4. Use wc -w for words, wc -c for bytes, and wc -m for characters (locale-aware).

Try this

Run printf 'é' | wc -c and printf 'é' | wc -m. On UTF-8, bytes and characters differ for that accented letter.

Why it works

Turn output into insight.

Open full demonstration ↗