Online Linux Terminal Logo
OnlineLinuxTerminal
Text ProcessingCLI Reference

$wc

Print newline, word, and byte counts for files.

Syntax DefinitionPOSIX standard
wc [OPTIONS] [FILE...]
Linux Community2.4k Online

Chat with real Linux users, learn new commands & get free cheat sheet PDFs.

Try `wc` Live in Interactive Sandbox

Zero-install client simulation with real-time feedback.

Open in Fullscreen Workspace↗
bash — terminal

Overview & How wc Works

`wc` (Word Count) reads files or standard input and computes statistics including line count (`-l`), word count (`-w`), and byte count (`-c`). It is widely used in shell pipelines to count query results or filter matches (e.g., `grep ... | wc -l`).

Common Flags & Command Options

Flag / OptionDescription
-lCount and print total newline line counts.
-wCount and print total words.
-cCount and print total bytes.
-mCount and print total characters.

Practical Real-World Examples

Example #1Count total lines in a file
wc -l welcome.txt

Outputs the line count for welcome.txt.

Sample Output:
15 welcome.txt
Example #2Count matching error occurrences in logs
grep "error" /var/log/syslog | wc -l

Pipes grep output into wc -l to get the exact integer count.

Frequently Asked Questions

Why does wc -l sometimes show 1 less line than expected?

`wc -l` counts newline (`\n`) characters. If the final line in a file lacks a trailing newline character, it is not counted as a full line.