Back to the command reference

wc

ShellBeginner In simulator In real Linux

Count lines, words and bytes

Name: wc = word count

You can practise it right away in the simulator, and use it in real Linux mode too.

Description

wc counts lines, words and bytes. The line count is really the number of newline characters, so a last line without one isn't counted.

It mostly ends pipelines that count things, e.g. grep ... | wc -l.

Syntax

wc [OPTION]... [FILE]...

Common options

-l / --linesCount lines
-w / --wordsCount words
-c / --bytesCount bytes
-m / --charsCount characters
-L / --max-line-lengthThe length of the longest line

Examples

  • $ wc -l data/fruits.txt

    How many lines a file has

    Explain
  • $ grep ERROR logs/app.log | wc -l

    Count the error lines

    Explain
  • $ ls | wc -l

    How many entries are in this directory

    Explain

Related