/ factorpad.com / tech / linux-essentials / wc-command.html
An ad-free and cookie-free website.
Beginner
Learn to count words, lines or bytes in a file at the Linux command line.
Videos can also be accessed from the Linux Essentials Playlist on YouTube.
Linux wc Command Summary with Examples (4:09)
Our twenty-sixth word, or command to memorize is wc
from our category
Text.
wc
allows you to count lines, words
and bytes.
-options | description |
---|---|
-l , --lines |
Count lines |
-w , --words |
Count words |
-c ,--bytes |
Count bytes |
Recall from the last video we spent time on navigation topics and now we'll shift back to text for a few videos.
Before we start, it helps to think about commands as mini programs and
most follow this structure:
command -option(s) argument(s)
.
The wc
command has
8 options and arguments are the files on which
you'd like to perform the count.
Like most commands, help is available with double-dash
--help
.
Without options wc
prints all three
: lines, then words, then bytes. To report only one count, use
-l
for lines,
-w
for words and make note, it's
-c
and not dash-b, for bytes.
So why is wc
an important command?
Well, wc
is helpful for monitoring
changes to files.
And now you know how to do that.
Okay, the best way to embed this in your memory is by typing in your own terminal window.
Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.
Here we go, let's start with the broadest view using the
wc *
which shows counts for all of our
files. Lines, words and bytes.
Second, let's create a file to process by grabbing the help file
wc --help
and output it
>
to a text file called
video26.txt
.
Now using wc -l
and count
22 lines.
Let's open with less
from video #5,
using the -N
option.
And look, the syntax, eight options and 22 lines.
Third, hit q
to leave
less
. For words
wc -w
on
video26.txt
160.
And last, to reinforce two things, byte count is dash
-c
, not dash-b. Also recall that
with double-dash, as long as Linux identifies what you mean, it'll
work. So --by
counts, pretty neat huh?
Okay now you know how to use wc
.
And you know the syntax for commands, options and arguments.
One last tip about the wc
command.
It really comes in handy to count programs or changes to the number
of lines in a log file.
Okay, thanks for visiting today. I hope this was a helpful
introduction to the wc
command.
For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:
Follow our YouTube Channel and @factorpad Twitter handle for updates on new opportunites to learn.
rm
command, hit
Back.head
command, click Next./ factorpad.com / tech / linux-essentials / wc-command.html
A newly-updated free resource. Connect and refer a friend today.