Go2Linux | Linux Operating System

A site dedicated to: Linux Operating System

Counting lines, words, characters in text files with Linux with wc

Date: 2007-04-14 00:00:00 -0400

There are a lot of useful tools in Linux wc is one of them this tool let us know the number of:

Lines words Characters

that we could find in a text file, its use is very simple, so if you are asking

How to count lines, how to count words or how to count characters, you can use this tool. Usage:

wc [OPTION]… [FILE]…

Where the options are

   -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


Suppose you have a file called mytextfile.txt and would like to know how many lines and words it have just enter:

wc -l -w mytextfile.txt

The output will be like this.

7334  22002 /home/user/mytextfile.txt

so it has 7334 lines and 22002 words.

powered by TinyLetter

If you want to contact me in any other way, please use the contact page.