Gice

Technology and General Blog

Linux comes with lots of pre-set up tools. The wc command is 1 of them. The term “wc” is an abbreviation of “word count”. As the title indicates, the wc command is for counting a variety of values of a file. These counts can appear in helpful in numerous cases.

In this guideline, test out employing the wc command with illustrations.

Linux wc command

The wc command is a tool that comes pre-put in in any Linux distro. It is a tool dedicated to counting many matters, for example, words, lines, people, and bytes. As for the input, it can be STDIN (regular input) or a file.

The guy page of wc explains all the accessible possibilities in detail.

Applying wc command

Wc command framework

This is the foundation construction of the wc command.

As for the enter, wc accepts zero or extra enter “FILE” names. If no name is specified, then wc will operate on STDIN.

Simple utilization
If no possibility is specified, then wc will print all the details about the input file: line, term, and character depend. If the input is a number of data files, then wc will print details about just about every of them individually.

For demonstration, we’ll use the GPL 3 license description. Test out GPL 3.

$ wget https://www.gnu.org/licenses/gpl-3..txt

Now, run wc on the textual content file.

The output is divided into 4 columns. Observe that wc will usually print the output in the next order.

  • Column 1: Line count.
  • Column 2: Phrase rely.
  • Column 3: Character depend.
  • Column 4: Filename and file path.

We can pipe the command’s output to wc to depend words and phrases, lines, people, and bytes. In such a predicament, even so, column 4 will be vacant.

Let’s see what occurs when there are multiple files as enter.

$ wc dummy.txt gpl-3..txt

Line depend
Though the wc command can print many info all at after, it is needless in most circumstances. We can separately test a variety of file info.

To check the number of traces in the file, use the flag “-l” or “–lines”.

Here’s how to examine the line depend of several documents.

$ wc –strains dummy.txt gpl-3..txt

Phrase depend
Despite the fact that we all have an innate being familiar with of what a word is, it’s important to comprehend the specialized definition to make sense of wc output. In the case of wc, a phrase does not have to be element of the dictionary. As a substitute, it is defined as a string of figures delimited utilizing house, tab, or newline.

To depend the phrase of a file, use the flag “-w” or “–words”.

Character depend
Use the flag “-m” or “–chars” to get the character rely of the input.

Byte rely
The wc command can also tell the dimensions of a file in bytes. A byte is a device comprising of 8 bits.

To get a byte depend of the concentrate on file/input, use the flag “-c” or “–bytes”.

Most line size
In the scenario of wc, a line can be any assortment of characters (a string) delimited by a new line. If there are many strains, then selected strains may well consist of a lot more figures than any other. We can use wc to get the size of the longest line in the enter.

To do so, use the flag “–max-line-length” or “-L”.

$ wc –max-line-size gpl-3..txt

Practical examples

So considerably, we have checked making use of the wc command only. Having said that, we can incorporate wc with other commands to get a lot more useful info. Listed here are a handful of illustrations.

Counting selection of information
We can use wc to depend the quantity of documents in a listing.

The trick is applying the obtain command and wc command in combination. The come across command will print the checklist of files in the directory, and wc will rely the traces. Verify out this in-depth manual on Linux obtain command.

$ discover -sort f | wc -l

Counting person quantities
In Linux, the file “/and many others/passwd” has all the consumers and user facts that use passwords as the authentication mechanism. By counting the selection of lines in the file, we can examine the number of customers currently in the program.

If users are configured to use LDAP as an authentication approach, these end users won’t appear in this file. To get the checklist of all the buyers, the getent command is a very good possibility.

The getent tool is devoted to exhibiting data stored in several administrative databases. Right here, “passwd” is the databases that holds all the person details. Discover far more about Linux getent command.

Ultimate thoughts

The wc command is a straightforward and simple-to-use device that comes in useful in numerous cases. It presents a brief depend of traces, words and phrases, bytes, and figures of a file.

However, a file has a lot more properties and parameters than that. The ls command can give you in-depth information about file permissions, spot, measurement, possession, and a lot more. Check out how to use Linux ls command.

Happy computing!

Leave a Reply

Your email address will not be published. Required fields are marked *