AMZ DIGICOM

Digital Communication

AMZ DIGICOM

Digital Communication

Linux wc command: count lines and characters

PARTAGEZ

With the Linux wc command, display the number of lines, words and characters in a file. This command can also be used on several documents, of which it then adds the values.

Linux wc command: what is it?

You wish find out the number of characters in your text files ? The Linux wc command is the easiest solution. This command, whose abbreviation means “word count”, runs on the command line and is one of the standard elements present in most Linux distributions, such as Debian or Ubuntu. The wc command is able to count bytes, words, and characters and display their count cumulatively or separately. Most writing programs offer a similar option. However, if you want to get these values ​​directly from the terminal and without having to go through any other software, the Linux wc command is ideal.

How does the wc command work?

We will quickly explain how the Linux wc command works. With this command, you get a precise list of the different parameters. You can set them using an option, otherwise they are listed by default. The default setting lets you specify the number of consecutive lines, words, and characters. The command can also be executed simultaneously on several text files. It then allows you to obtain the total value of the different lines, words and characters in a cumulative way, in addition to a default list of the different documents.

What does the wc command syntax look like?

Below is the syntax of the Linux wc command:

$ wc [Option] [Fichier]

shell

If you decide not to use options, the result follows the aforementioned pattern of number of lines, words and characters. If you don’t specify a file, then the command automatically refers to standard input.

What are the options offered by Linux wc?

You can use different options to specify the wc command.

  • -vs : it only counts the bytes within a file.
  • -L : it displays the length of the longest line.
  • -L : it only counts the lines within a file.
  • -m: it displays only the characters within a file.
  • -w: it only counts the words within a file.

wc command: examples

Finally, we will show you how to integrate the Linux wc command into your daily work with some practical examples.

This command displays the number of lines, words and characters in the document example.txt.

$ wc exemple.txt index.html

shell

This command first displays the individual values ​​for each file, as shown above. The final result contains a row that summarizes the total for both documents.

This command displays only the number of words contained in the document example.py.

Télécharger notre livre blanc

Comment construire une stratégie de marketing digital ?

Le guide indispensable pour promouvoir votre marque en ligne

En savoir plus

Souhaitez vous Booster votre Business?

écrivez-nous et restez en contact