MilkySEO logomilkyseo
Word counter

What Is the Word Count Command in Linux, Mac & Terminal?

MilkySEO Editorial Team12 min readUpdated June 22, 2026

In this article, you will learn how to count words, lines, characters, and bytes in Linux and Mac using the wc command with simple examples using the terminal.

Quick Summary

  • In Linux and Mac Terminal, the wc command is used to count the number of lines/words/bytes/characters inside a text file.
  • If left to its default,wc file.txt will display the number of lines, words, and bytes in the file as well as the name of the file.
  • To count words, use wc -w ; to count lines, use wc -l; to count characters, use wc -m ; and to count bytes, use wc -c .
  • This is because the difference between wc -c and wc -m can differ as bytes and characters can be distinct in Unicode or non-English text.
  • The number of lines of command output or lines that match a pattern could be counted using a pipe with wc, e.g. grep "error" app.log | wc -l.

Basic Syntax of the wc Command

The basic syntax is:

wc [option] [file]

Example:

wc file.txt

Output:

10  85  520 file.txt

By default, wc shows three values:

Output PositionMeaning
First valueNumber of lines
Second valueNumber of words
Third valueNumber of bytes

So, in this example:

10  85  520 file.txt

means the file has 10 lines, 85 words, and 520 bytes.

The easiest way that I know to remember the command is wc [option] [file] the option says what to count, the file name says where to count.

Common wc Command Options

WC command options infographic showing how to count words, lines, characters, bytes, and default file output in Linux Terminal.
CommandPurposeExample
wc -wCount wordswc -w file.txt
wc -lCount lineswc -l file.txt
wc -cCount byteswc -c file.txt
wc -mCount characterswc -m file.txt
wc file.txtCount lines, words, and byteswc file.txt

How to Count Words in Linux or Mac Terminal?

To count words in a file, use:

wc -w file.txt

Example:

wc -w article.txt

Output:

1250 article.txt

This means article.txt contains 1,250 words.

How to Count Lines in a File?

To count lines, use:

wc -l file.txt

Example:

wc -l app.log

This is useful for counting lines in log files, CSV files, code files, or text documents.

How to Count Characters?

To count characters, use:

wc -m file.txt

Example:

wc -m content.txt

Use this when you want the actual character count of a text file.

How to Count Bytes?

To count bytes, use:

wc -c file.txt

Example:

wc -c data.txt

Bytes and characters are not always the same. In simple English texts, they are often equal. In Unicode text, one character may use more than one byte.

Difference Between wc -c and wc -m

OptionCountsBest Used For
wc -cBytesFile size or byte-level text analysis
wc -mCharactersActual character count in text

Example:

wc -c file.txt
wc -m file.txt

Use wc -m for character count and wc -c for byte count.

Using wc with Pipes

The wc command can also count output from another command.

Example:

echo "Linux terminal is useful" | wc -w

Output:

4

You can also count files in a directory:

ls | wc -l

This counts how many items are listed in the current directory.

Count Matching Lines with grep and wc

You can combine grep with wc to count matching lines.

Example:

grep "error" app.log | wc -l

This counts how many lines contain the word error.

For case-insensitive search:

grep -i "error" app.log | wc -l

Linux vs Mac wc Command

Infographic explaining the word count wc command in Linux, Mac, and Terminal with options, use cases, and command examples.

The wc command works almost the same on Linux and Mac Terminal.

FeatureLinuxMac
Word countwc -w file.txtwc -w file.txt
Line countwc -l file.txtwc -l file.txt
Byte countwc -c file.txtwc -c file.txt
Character countwc -m file.txtwc -m file.txt
Default versionGNU wcBSD wc

For basic word, line, character, and byte counting, there is no major difference between Linux and Mac.

How to Show Only the Number

By default, wc shows the count and filename:

wc -w file.txt

Output:

500 file.txt

To show only the number, use input redirection:

wc -w < file.txt

Output:

500

This is useful in shell scripts.

Practical Examples

TaskCommand
Count words in a filewc -w file.txt
Count lines in a filewc -l file.txt
Count characters in a filewc -m file.txt
Count bytes in a filewc -c file.txt
Count files in a folderls | wc -l
Count matching log linesgrep "error" app.log | wc -l
Count words without filenamewc -w < file.txt

The most important commands are:

CommandUse
wc -w file.txtCount words
wc -l file.txtCount lines
wc -m file.txtCount characters
wc -c file.txtCount bytes

For most users, wc -w file.txt is the main command for checking word count, while wc -l, wc -m, and wc -c are useful for line, character, and byte counts.

If you are comparing terminal counts with writing-app counts, you may also want the guides for checking word count on Mac and word count vs character count.

Interesting Research Facts

Full citations are in Sources below.

Unix pipeline design

wc processes text streams sequentially, and will be useful with other text stream processors such as grep, find, and pipes to filter the text stream before counting.

Source: Unix pipeline design

Buffered I/O efficiency

wc reads in chunks of data for processing, which means that counting lines, words, bytes, and characters is both fast and doesn't require a lot of memory.

Source: Buffered I/O efficiency

Word definition

The word definition for wc is defined as a non-empty sequence of non-whitespace characters, not as defined by dictionary.

Source: Word definition

wc -l counts newlines

A file containing no newline character will have one line less than the number of newlines you expect in it.

Source: wc invocation - GNU Coreutils Manual

Log-processing use case

In commands such as grep "ERROR" access.log | wc -l, grep, the operation of filtering is typically done by the command grep, and the operation of counting is typically done by the command wc.

Source: Log-processing use case

Frequently Asked Questions

1.What is wc?

wc is used to count the number of lines, words, bytes and characters in a file or terminal output.

2.Why are there three numbers when using wc file.txt?

If you do not use any options, the default behavior of wc is to print the number of lines, words, and bytes.

3.How to count just the lines that exist in a file?

Count just the lines: wc -l file.txt.

4.How to display the number but not the file name?

Input redirection can be done like this: wc -w < file.txt.

5.What is the difference between wc -c and wc -m?

The wc -c will count bytes, and the wc -m will count characters. They may vary in the Unicode text.

6.Why does echo "k" | wc -c show 2 instead of 1?

The character count goes in the range; when you use echo, it's putting a line break after k, so that wc -c counts the character and the line break.

7.What does ls | wc -l do?

Counts the number of items in the current directory.

8.Can I use wc with grep?

Yes. The following command, for instance, will return the number of lines in the file app.log that have the word error in them: grep "error" app.log | wc -l

How we reviewed this article:

Share this article

Written by

Muneeb Maqsood

SEO Expert, AEO & GEO Specialist

Muneeb Maqsood is an SEO Expert, AEO & GEO Specialist with over 5 years of experience focused on delivering measurable business growth. He helps brands improve search visibility, attract qualified leads, and most importantly, convert organic traffic into paying customers through strategic, intent-driven optimization.

He has worked with and helped grow multiple established brands including Viking Bags, Elite Sports, and GForce Security, delivering performance-focused SEO strategies that improve rankings, visibility, and conversions. His work is centered on turning SEO into a revenue channel by aligning search intent with business outcomes and sustainable growth.

More Word counter guides from the MilkySEO blog.

View all posts
What Is the Word Count Command in Linux, Mac & Terminal? | MilkySEO