$linuxjunkies
>

wc(1)

Count lines, words, and characters in files or standard input.

UbuntuDebianFedoraArch

Synopsis

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

Description

The wc command counts newlines, words, and bytes (or characters) in one or more files, or reads from standard input if no file is specified. By default, it displays all three counts plus the filename.

A word is defined as a string of characters delimited by whitespace (spaces, tabs, or newlines). Lines are counted by the number of newline characters encountered.

Common options

FlagWhat it does
-lPrint only the newline (line) count
-wPrint only the word count
-cPrint only the byte count
-mPrint only the character count (differs from -c for multibyte chars)
-LPrint the length of the longest line
--files0-from=FILERead filenames from FILE, one per line, null-terminated

Examples

Show line, word, and byte counts for file.txt

wc file.txt

Count total lines across all .log files

wc -l *.log

Count words in file.txt using stdin

cat file.txt | wc -w

Show the length of the longest line in file.txt

wc -L file.txt

Count running processes (including header)

ps aux | wc -l

Count total lines of code in all Python files

find . -name '*.py' | xargs wc -l

Show byte count (useful for binary files)

wc -c file.txt

Show counts for each file plus a total line

wc file1.txt file2.txt file3.txt

Related commands