fbpx wc Command in Linux: Count Lines, Words, and Characters | Certificação Linux

Linux wc Command: Count Lines, Words, and Characters in Files

📅 01/01/2019 ⏱ 1 min ✍️ Uira Ribeiro
Linuxcommands
Linux wc Command: Count Lines, Words, and Characters in Files
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

The wc command in Linux shows the lines, words, and number of characters in a file, in that 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 of one or more files. If more than one file is passed as an argument, it will display the statistics for each file and the total.

The most common options are:

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

In this example, we will use wc to count the unique items in the grocery list:

$ sort supermercado | uniq | wc
      6       6      41

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

Learn much more about Linux in our online course. You can enroll here. If you already have an account, or want to create one, just log in or create your user here.

Did you like it? Share

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp