Home·Terminal commands

wc

Text processing

Usage

wc -l [file]

Counts lines, words and bytes; -l counts newline characters, so a final line with no newline is not counted.

Common flags

FlagMeaning
-lCount lines, meaning newline characters
-wCount words
-cCount bytes
-mCount characters, which differs from -c outside ASCII
-LLength of the longest line

Examples

wc -l *.ts

Line count per file plus a total.

ls | wc -l

How many entries this directory holds.

These were built to be piped together. Three joined commands are usually shorter than one that does everything.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does wc do?

Counts lines, words and bytes; -l counts newline characters, so a final line with no newline is not counted.

Q. How do I type it?

wc -l [file] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

5 are listed here; the full set is in man wc. This command sits under Text processing.

Related commands

man page: man wc