wc (Word Count) command in Linux is a versatile utility that displays the
number of lines, words, and bytes contained in a file or received via a pipe.
Whether you're a system administrator, programmer, or end user,
wc can greatly augment your text-manipulation prowess. This
article explores the syntax, options, and examples to help you get the most out
The basic syntax for the
wc command is as follows:
wc [OPTION]... [FILE]...
OPTION: Flags that modify the behavior of
FILE: The file(s) to operate on. If this parameter is omitted,
wcreads from standard input.
Here is a table outlining some commonly used options, their shorthand, and what they do:
|The maximum display width|
If you have a file called
How are you today?
wc to get lines, words, and bytes:
2 8 32 example.txt
This means 2 lines, 8 words, and 32 bytes.
To count only lines, use the
wc -l example.txt
To count only words, use the
wc -w example.txt
To count only characters, use the
wc -m example.txt
To count only bytes, use the
wc -c example.txt
Find Maximum Line Length
To find the maximum line length, use the
wc -L example.txt
Combining Multiple Options
You can combine options for more detailed statistics:
wc -lw example.txt
2 8 example.txt
Using with Pipes
wc command can also work with other commands through a pipe. For instance,
to count the number of files in a directory, you could do:
ls | wc -l
wc command is a powerful utility with a straightforward interface, making
it incredibly useful for a variety of text-manipulation tasks. Its options to
count lines, words, characters, or bytes give it versatility. Furthermore, it
plays nicely with other text and file manipulation commands, amplifying its
wc will certainly upgrade your Linux command-line
What Can You Do Next 🙏😊
If you liked the article, consider subscribing to Cloudaffle, my YouTube Channel, where I keep posting in-depth tutorials and all edutainment stuff for software developers.