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
| Flag | Meaning |
|---|---|
| -l | Count lines, meaning newline characters |
| -w | Count words |
| -c | Count bytes |
| -m | Count characters, which differs from -c outside ASCII |
| -L | Length of the longest line |
Examples
wc -l *.tsLine count per file plus a total.
ls | wc -lHow 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