An ad-free and cookie-free website.
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
wc allows you to count lines, words
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).
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
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?
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
wc -l and count
Let's open with
less from video #5,
And look, the syntax, eight options and 22 lines.
q to leave
less. For words
wc -w on
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
--by counts, pretty neat huh?
Okay now you know how to use
And you know the syntax for commands, options and arguments.
One last tip about the
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
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.
rmcommand, hit Back.
headcommand, click Next.
A newly-updated free resource. Connect and refer a friend today.