Beginner Package: coreutils

wc

Count lines, words and bytes in a file.

Syntax

wc [options] file

Description

wc (word count) reports the number of lines, words and bytes in a file or piped input, and is frequently used at the end of a pipeline to count how many results matched.

Examples

wc -l file.txt
Count the number of lines in a file
ls | wc -l
Count how many files are in a directory
grep -c "error" file.log
(Related) grep's own built-in match counter

Applies to

Ubuntu Debian Linux Mint RHEL CentOS / Rocky / AlmaLinux Fedora Arch Linux openSUSE Alpine Linux