Skip to content

wc

10 commands

Counts lines, words, characters and bytes in files or input.

  • counting
  • text

Install wc

sudo apt install coreutils

Basics7

wc <file>

Prints line, word and byte counts.

Link
wc -l <file>

Counts lines.

Link
wc -w <file>

Counts words.

Link
wc -c <file>

Counts bytes.

Link
wc -m <file>

Counts characters, which differs from bytes for multi-byte text.

Link
wc -L <file>

Prints the length of the longest line (GNU).

Link
wc -l *.txt

Counts several files and adds a total.

Link

In pipelines3

<command> | wc -l

Counts lines of output.

Link
grep -c "<pattern>" <file>

Counting matches directly is faster than grep | wc -l.

Link
find <dir> -type f | wc -l

Counts files under a directory.

Link