wc counts the lines, words and bytes in a file. Learn how to count log lines, how to count what `grep` found, and how to get the number on its own, by running the commands in a real terminal in your browser.
Updated: 2026-09-06
wc [options] file...
With no options it prints lines, words and bytes, in that order.
$ wc logs/app.log
10 28 200 logs/app.log
That is 10 lines, 28 words and 200 bytes.
| Option | What it counts |
|---|---|
-l | Lines |
-w | Words |
-c | Bytes |
-l is the one you will use almost every time.
$ wc -l logs/app.log
10 logs/app.log
Words and bytes work the same way.
$ wc -w notes.txt
9 notes.txt
$ wc -c notes.txt
41 notes.txt
List more than one file and you get a total at the end.
$ wc -l users.csv notes.txt
4 users.csv
3 notes.txt
7 total
Patterns such as *.csv work too.
$ wc -l *.csv
4 users.csv
wc earns its place at the end of a pipe.
$ grep ERROR logs/app.log | wc -l
3
Three lines matched.
To count files, pipe ls into it.
$ ls | wc -l
4
Pass a file name and wc prints the name back with the count.
Feed the contents in with < and there is no name to print, so you get the number alone.
$ wc -l < logs/app.log
10
That is the form to use when a script needs the count in a variable.
wc is what you type to decide whether something is a lot or a little.
| Situation | What to type |
|---|---|
| Count the errors in a log | grep ERROR app.log | wc -l |
| Check how long a file is before opening it | wc -l app.log |
| Count the files in a directory | ls logs | wc -l |
| Count files matching a pattern | find . -name "*.js" | wc -l |
| Get the number by itself | wc -l < app.log |
If you only need the count, grep -c is shorter.
$ grep -c ERROR logs/app.log
3
Same number as grep ... | wc -l.
Pipe when you also want to see the matching lines, use -c when you only want how many.
-c counts bytes, not characters.
Text with multi-byte characters in it will not match what you would count by eye.
Directories cannot be counted.
$ wc -l logs
wc: logs: Is a directory
To count what is inside one, use ls logs | wc -l.
A missing file says so.
$ wc -l nope.txt
wc: nope.txt: No such file or directorywebterm.appthis site
Advanced Terminal Commands
Learn commands for specific situations
learn.webterm.appa separate site

Commands stick when they show up in a real sequence of work, not one at a time. There is a course that builds them up in order.
See the course