wc
How many lines in this file, how many errors in this log, how many files in this folder? wc -l answers.
>_ Try it: a simulated Linux, right herenothing runs on your computer
Loading the terminal…
Examples
-
wc app.log -
wc -l users.csv -
grep ERROR app.log | wc -l -
ls /etc | wc -l -
wc -w app.log
How it works
wc FILE prints three counts: lines, words and bytes (characters), then the name. Most of the time you want just one, so add -l, -w or -c.
Its real power is at the end of a pipe: grep ERROR app.log | wc -l counts the error lines, ls | wc -l counts what is in a folder.
Syntax
wc [-l] [-w] [-c] [FILE]...
Options
| Option | What it does |
|---|---|
-l | count lines |
-w | count words |
-c | count bytes (characters, for plain text) |
Good to know
- A CSV with a header row has one data row fewer than
wc -lsays. grep -c ERROR app.logcounts matching lines too, without the pipe.