wc: count lines, words and characters

Updated November 2026

wc (word count) counts lines, words and bytes. Its most common use is wc -l: how many lines, and therefore how many log entries, users, files or matches.

wc [-l] [-w] [-c] [-m] [file ...]

Examples

wc report.txt                     # lines, words, bytes, name
wc -l /etc/passwd                 # number of lines (accounts)
wc -l *.py                        # lines per file and a total
wc -w essay.txt                   # words
wc -c image.png                   # bytes
wc -m notes.txt                   # characters (differs from bytes for UTF-8 text)
wc -L file.txt                    # length of the longest line (GNU)
grep -c error app.log             # count matching lines: grep can do it itself
find . -type f | wc -l            # number of files in a tree
ls /etc | wc -l                   # entries in a directory

In scripts

wc -l file prints the file name too. To get just the number, read from standard input. BSD and macOS still pad the number with spaces, so strip them to be portable:

count=$(wc -l < access.log | tr -d ' ')
echo "$count requests"

wc -l counts newline characters, so a file whose last line has no newline at the end reports one line fewer than you might expect.