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

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Ravi Saive

I am Ravi Saive, creator of TecMint. A Computer Geek and Linux Guru who loves to share tricks and tips on Internet. Most Of My Servers runs on Open Source Platform called Linux. Follow Me: Twitter, Facebook and Google+

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

23 Responses

  1. saurabh Madhukar says:

    Thank you sir, very helpful article.

  2. Ezza Kezza says:

    Help,

    This all looks very straightforward if you know what you’re doing. Whereabouts do I type in the command wc -w to try and find out how many words are in a document, please?

    I’d greatly appreciate step by step from the beginning, pics would be good :)

    • Ravi Saive says:

      @Ezza,

      Here is the example command of how wc -c works.

      $ wc -w w_syst02.pdf 
      
      76522 w_syst02.pdf
      

      Here 76522 are number of words in a document w_syst02.pdf.

      • T-T-T says:

        can you help me…this is the code i’ve made..but i want to count the lines of 01:19:21….how to write the code just to count
        the all 01:19:21 lines????
        11:01:11
        03:53:28
        01:19:21
        01:19:21
        01:19:21
        01:19:21
        01:19:21
        01:19:21
        01:19:21
        01:19:21

  3. abhishek says:

    Write a shell script to count the number of lines, characters, words in a file (without the use of commands). Also delete the occurrence of word “Linux” from the file wherever it appears and save the results in a new file.
    anybody plz help

  4. Kinjal says:

    It is really helpful now. If I have any type of query , I will definitely ask u. Thanks for now.

  5. vijay vikky says:

    what is the special purpose for linux?

  6. hasan0228 says:

    How do I get no of records of the file exclude footer?

    • Ravi Saive says:

      @Hasan,

      Your question is incomplete, could you explain your question in more detailed fashion, so that we can understand better and give you a proper solution..

    • vikky says:

      use linux

      • David says:

        The tool for excelency is a computer (smartphone, tablet, etc) and need a software in special to work, to interactive with you like user. The best option to handle that is Linux. That is the reason.

  7. Sunny says:

    cat filename.txt | grep -v “saerch” | sed -n ‘ $ p ‘

  8. Saransh says:

    If u don’t want to print to print the last line

    Go for grep -v option

    can try grep -v ‘^6’

  9. Jayanto says:

    When I do a wc -l in a directory then the output is something like –
    1 File1.txt
    2 File2.txt
    3 File3.txt
    6 Total

    I do not want to display the last Total. How can we do that? Any insights..!

    • You can try this

      wc file*|grep -v total

      grep with -v option removes the lines which have the word “total” in them., so except last line all files with word count will shown. Hope it helps

  10. SRI says:

    Please tell me how to display number of words in each line by using wc command?

    • while read line; do echo “$line” | wc -m ;done < filename

      if your file contains '/' then use 'read -r' in the above command

      Another simple way without wc is

      awk '{print length($0) }' filename

Leave a Reply to SRI Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.