Categories: Text Tools

WC command on Linux (word count) [Basic Guide]

The wc command on Linux shows the lines, words, and number of characters in a file, in this order.

Suppose you want to count the number of lines, words, or characters in a file. The wc command can be used to count the lines, words, and characters in one or more files. If more than one file is passed as an argument, it will show the statistics for each file and the total.

The most common options are:

  • -c: Count the number of characters in one or more files;
  • -l: Count the number of lines in one or more files;
  • -L: Count the number of characters in the longest line of the file;
  • -w: Count the words in one or more files.

In this example, we are going to use the toilet to count the unique items on the grocery list:

$ sort supermarket | uniq | wc 

6 6 41

Our list has 6 items (one per line), six words, and 41 characters.

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Share
Published by
Uirá Endy Ribeiro

Recent Posts

Sudo command on Linux (privilege scale) [Basic Guide]

The sudo command on Linux executes a given command as if it were another user.…

2 years ago

SS command on Linux (investigate the network) [Basic Guide]

The ss command on Linux is extremely useful for investigating sockets, providing various information about…

2 years ago

Free Linux command (memory usage) [Basic Guide]

Free Linux command shows the amount of total memory in use and available, as well…

2 years ago

Linux while command (loop – while) [Basic Guide]

The shell has structures for testing conditions and executing certain program sequences several times (loop),…

2 years ago

Linux fstab file (disk mount setup) [Basic Guide]

The /etc/fstab file stores the configuration of which devices should be mounted and what is…

2 years ago

Netcat command on Linux (Swiss network knife) [Basic Guide]

The Netcat Command in Linux or nc is a utility used to do “almost anything”…

2 years ago

This website uses cookies.