Robert Elder Software Inc.
  • Home
  • Store
  • Blog
  • Contact
  • Home
  • Store
  • Blog
  • Contact
  • #linux
  • |
  • #commandline
  • |
  • #softwareengineering
  • |
  • #embeddedsystems
  • |
  • #compilers
  • ...
  • View All >>

Intro To 'wc' Command In Linux

2023-05-07 - By Robert Elder

     I use the 'wc' command to count the number of words or lines in a file:

wc -w file.txt  # Word count
wc -l file.txt  # Line count
wc -c file.txt  # Byte count

     Here, I have some text in the file 'story.txt':

The Industrial Revolution and its consequences have been really great
for the human race, because now we have indoor plumbing and candy corn.

Count Words In File With 'wc' Command

     I can count the number of words in the file using this command:

wc -w story.txt

     and the result shows that there are 23 words in the file 'story.txt':

23 story.txt

Count Lines In File With 'wc' Command

     I can also use the '-l' flag to count the number of lines in the file:

wc -l story.txt

     and the result shows that there are 2 lines in the file 'story.txt':

2 story.txt

Count Bytes In File With 'wc' Command

     If I use the '-c' flag, I'll see a count that shows the number of bytes in the file:

wc -c story.txt

     and the result shows that there are 142 bytes in the file 'story.txt':

142 story.txt

Using 'wc' With Multiple Files

     Let's add one more file called 'main.c' that contains the following text:

#include <stdio.h>

int main(){
	return 0;
}

     You can run the 'wc' command on multiple files at once to see individual and aggregate counts:

wc -l story.txt main.c

     and the output is as follows:

  2 story.txt
  5 main.c
  7 total

Default Usage of 'wc' Command

     If you don't use any flags with the 'wc' command you'll see all three counts together:

wc story.txt

     The first number is newline count, followed by the word count, and finally the byte count:

  2  23 142 story.txt

     And that's why the 'wc' command is my favourite Linux command.

Intro To 'stty' Command In Linux
Intro To 'stty' Command In Linux
Published 2023-10-04
Terminal Block Mining Simulation Game
$1.00 CAD
Terminal Block Mining Simulation Game
Intro To 'nproc' Command In Linux
Intro To 'nproc' Command In Linux
Published 2023-07-15
Intro To 'comm' Command In Linux
Intro To 'comm' Command In Linux
Published 2023-09-06
How To Force The 'true' Command To Return 'false'
How To Force The 'true' Command To Return 'false'
Published 2023-07-09
A Surprisingly Common Mistake Involving Wildcards & The Find Command
A Surprisingly Common Mistake Involving Wildcards & The Find Command
Published 2020-01-21
A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
Published 2019-08-01
Intro To 'chroot' Command In Linux
Intro To 'chroot' Command In Linux
Published 2023-06-23
Join My Mailing List
Privacy Policy
Why Bother Subscribing?
  • Free Software/Engineering Content. I publish all of my educational content publicly for free so everybody can make use of it.  Why bother signing up for a paid 'course', when you can just sign up for this email list?
  • Read about cool new products that I'm building. How do I make money? Glad you asked!  You'll get some emails with examples of things that I sell.  You might even get some business ideas of your own :)
  • People actually like this email list. I know that sounds crazy, because who actually subscribes to email lists these days, right?  Well, some do, and if you end up not liking it, I give you permission to unsubscribe and mark it as spam.
© 2025 Robert Elder Software Inc.
SocialSocialSocialSocialSocialSocialSocial
Privacy Policy      Store Policies      Terms of Use