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

The wc (word count) command in Unix/Linux operating systems is used to find out number of newline count, word count, byte and characters count in a files specified by the file arguments. The syntax of wc command as shown below.

# wc [options] filenames

The following are the options and usage provided by the command.

wc -l : Prints the number of lines in a file.
wc -w : prints the number of words in a file.
wc -c : Displays the count of bytes in a file.
wc -m : prints the count of characters from a file.
wc -L : prints only the length of the longest line in a file.

So, let’s see how we can use the ‘wc‘ command with their few available arguments and examples in this article. We have used the ‘tecmint.txt‘ file for testing the commands. Let’s find out the output of the file using cat command as shown below.

[[email protected] ~]# cat tecmint.txt

Red Hat
Scientific Linux
Linux Mint
Pearl Linux

1. A Basic Example of WC Command

The ‘wc‘ command without passing any parameter will display a basic result of ”tecmint.txt‘ file. The three numbers shown below are 12 (number of lines), 16 (number of words) and 112 (number of bytes) of the file.

[[email protected] ~]# wc tecmint.txt

12  16 112 tecmint.txt

2. Count Number of Lines

To count number of newlines in a file use the option ‘-l‘, which prints the number of lines from a given file. Say, the following command will display the count of newlines in a file. In the output the first filed assigned as count and second field is the name of file.

[[email protected] ~]# wc -l tecmint.txt

12 tecmint.txt

3. Display Number of Words

Using ‘-w‘ argument with ‘wc‘ command prints the number of words in a file. Type the following command to count the words in a file.

[[email protected] ~]# wc -w tecmint.txt

16 tecmint.txt

4. Count Number of Bytes and Characters

When using options ‘-c‘ and ‘-m‘ with ‘wc‘ command will print the total number of bytes and characters respectively in a file.

[[email protected] ~]# wc -c tecmint.txt

112 tecmint.txt
[[email protected] ~]# wc -m tecmint.txt

112 tecmint.txt

5. Display Length of Longest Line

The ‘wc‘ command allow an argument ‘-L‘, it can be used to print out the length of longest (number of characters) line in a file. So, we have the longest character line (‘Scientific Linux‘) in a file.

[[email protected] ~]# wc -L tecmint.txt

16 tecmint.txt

6. Check More WC Options

For more information and help on the wc command, simple run the ‘wc –help‘ or ‘man wc‘ from the command line.

[[email protected] ~]# wc --help

Usage: wc [OPTION]... [FILE]...
  or:  wc [OPTION]... --files0-from=F
Print newline, word, and byte counts for each FILE, and a total line if
more than one FILE is specified.  With no FILE, or when FILE is -,
read standard input.
  -c, --bytes            print the byte counts
  -m, --chars            print the character counts
  -l, --lines            print the newline counts
  -L, --max-line-length  print the length of the longest line
  -w, --words            print the word counts
      --help			display this help and exit
      --version			output version information and exit

Report wc bugs to [email protected]
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'wc invocation'

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

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

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
The Complete Linux System Administrator Bundle
Become an Ethical Hacker Bonus Bundle

You may also like...

24 Responses

  1. saurabh Madhukar says:

    Thank you sir, very helpful article.

  2. Ezza Kezza says:


    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:


      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????

  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:


      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 Ezza Kezza 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.