Linux WC Command Examples to Count Number of Lines, Words, Characters

The wc command (word count) is a fundamental Linux utility for counting lines, words, characters, and bytes in files. It's commonly used with the -l option for line counting, but offers several other counting options through various arguments.

Available Options

Option Command Function
1 wc -c Display number of bytes
2 wc -m Display number of characters
3 wc -w Display number of words
4 wc -l Display number of lines
5 wc -L Display length of longest line

Let's consider the following sample file for our examples ?

ubuntu@ubuntu:~$ cat inspire.txt
Mastering anything needs practice.
It aslo needs patience.
And it needs time and other resources.

Count Bytes (-c Option)

Display the number of bytes in the file ?

ubuntu@ubuntu:~$ wc -c inspire.txt
98 inspire.txt

Count Characters (-m Option)

Display the number of characters in the file ?

ubuntu@ubuntu:~$ wc -m inspire.txt
98 inspire.txt

Count Words (-w Option)

Display the number of words in the file ?

ubuntu@ubuntu:~$ wc -w inspire.txt
15 inspire.txt

Count Lines (-l Option)

Display the number of lines in the file ?

ubuntu@ubuntu:~$ wc -l inspire.txt
3 inspire.txt

Longest Line Length (-L Option)

Display the length of the longest line in the file ?

ubuntu@ubuntu:~$ wc -L inspire.txt
38 inspire.txt

Default Output (No Options)

When used without options, wc displays lines, words, and characters in that order ?

ubuntu@ubuntu:~$ wc inspire.txt
3 15 98 inspire.txt

The output shows: 3 lines, 15 words, and 98 characters in the file.

Conclusion

The wc command is essential for text file analysis in Linux. Use -l for line counting, -w for word counting, and combine options like wc -lw for multiple counts simultaneously.

Updated on: 2026-03-15T17:26:19+05:30

563 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements