Skip to main content

wc

The wc (word count) command prints the number of newlines, words, and bytes for each given file. If multiple files are specified, it also prints a total line.

Basic Syntax

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

Common Options

OptionDescription
-l, --linesPrint the newline counts.
-w, --wordsPrint the word counts.
-c, --bytesPrint the byte counts.
-m, --charsPrint the character counts.

Real-world Examples

  1. Count lines, words, and bytes in a file:

    wc document.txt
  2. Count only the number of lines:

    wc -l file.txt
  3. Count the number of files in a directory:

    ls -1 | wc -l
  4. Count words in a string using standard input:

    echo "Hello world" | wc -w