File Viewing & Editing

wc

Print newline, word, and byte counts for each file.

Synopsis

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

Examples

Show lines, words, and bytes
wc file.txt
Count lines in all Python files
wc -l *.py
Count lines from piped input
cat log.txt | wc -l
Count number of TypeScript files
find . -name '*.ts' | wc -l

Common options

FlagDescription
-lPrint line count
-wPrint word count
-cPrint byte count
-mPrint character count
-LPrint length of longest line

About wc

The `wc` command print newline, word, and byte counts for each file. Text viewing and editing commands are fundamental tools in any Linux user's toolkit.

Linux treats almost everything as a file, so the ability to quickly inspect, filter, transform, and edit file contents from the command line is critical. These commands are regularly combined with pipes and redirects to build powerful data-processing pipelines.

The command accepts 5 commonly used flags shown above, though the full set of options is available in the man page (`man wc`). The 4 examples on this page cover typical real-world usage patterns that you can copy and adapt for your own workflows.

Related commands

More File Viewing & Editing Commands

Other commands in the File Viewing & Editing category

Related tools