← Linux command list

wc command: count lines, words and bytes

__ __ _ _____
\ \ / /__| |_|_ _|__ _ __ _ __ ___
\ \ /\ / / _ \ '_ \| |/ _ \ '__| '_ ` _ \
\ V V / __/ |_) | | __/ | | | | | |
\_/\_/ \___|_.__/|_|\___|_| |_| |_| |_
 
A sandbox for trying wc. Nothing here can touch your real files.
user@webterm:~/project$
 

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

Syntax

wc [options] file...

With no options it prints lines, words and bytes, in that order.

Try it first

$ wc logs/app.log
 10  28 200 logs/app.log

That is 10 lines, 28 words and 200 bytes.

OptionWhat it counts
-lLines
-wWords
-cBytes

-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

Counting several files at once

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

Counting what another command found

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

Getting the number on its own

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.

When you actually reach for it

wc is what you type to decide whether something is a lot or a little.

SituationWhat to type
Count the errors in a loggrep ERROR app.log | wc -l
Check how long a file is before opening itwc -l app.log
Count the files in a directoryls logs | wc -l
Count files matching a patternfind . -name "*.js" | wc -l
Get the number by itselfwc -l < app.log

Things that trip people up

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 directory

Practise it hands-on

webterm.app

  • Advanced Terminal Commands

    Learn commands for specific situations

    Try the tutorial

learn.webterm.app

>_WEBTERM LEARN

WebTerm Learn: from one command to actually using it

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

Related commands

grep / sort / cat / find

wc is also in the “Search and inspect” section of the Linux Commands Cheat Sheet.

Frequently asked questions

What does wc stand for?
Word count. In practice though the flag you reach for is `-l`, counting lines, to find out how many log entries or files you are dealing with.
What are the three numbers?
Lines, words and bytes, in that order. Add `-l`, `-w` or `-c` to print just one of them.
How do I get the number without the file name?
Feed the file in with `<`, as in `wc -l < file`. Given a file name wc prints it back; given standard input it has no name to print.
How do I count what grep found?
`grep ERROR app.log | wc -l` works. `grep -c ERROR app.log` gives the same number and is shorter when counting is all you want.
What happens if I pass a directory?
You get `wc: logs: Is a directory`. To count the files inside it, pipe instead: `ls logs | wc -l`.