9 wc Command Examples in Linux (Complete Guide)

国内高佣广告联盟 熊掌联运广告联盟 最新域名优惠/VPS优惠/免备案CDN活动

Today in this guide you will learn how to use wc command in Linux.

wc stands for Word Count.

As you can understand from the name itself, wc command is used to count the available words in the contents of a file.

Not only this, wc has more features which we are going to discuss in this article.

With the help of wc you can collect the following information of a file:

  • Word Counts
  • Byte Counts
  • Character Counts
  • Newline Counts
  • Maximum Display Width

Syntax:

You must follow the syntax given below to use the wc command.

wc [OPTION]... [FILE]...

wc [OPTION]... --files0-from=F

1. How to use the wc Command?

Here I have a file named months.txt which contains some content. You can display the contents of this file using cat command.

With the help of this, I will explain this concept to you.

~$ cat months.txt

### Months of the Year ###

January
February
March
April
May
June
July
August
September
October
November
December

By default the wc command prints the following information without any option.

Word Counts
Byte Counts
Character Counts
Line Counts

Example:

~$ wc months.txt 
 15  18 115 months.txt

If you don’t want to print the filename type the following command.

~$ wc < months.txt 
 14  18 114

Now lets Print Line, Word, and Byte counts present in multiple files. Here is an example:

2. Print the Word Counts

To print the count of the Words present in a file, Pass the -w option to wc.

~$ wc -w months.txt 
18 months.txt

You can also use the long option --words.

~$ wc --words months.txt

3. Print the Byte Counts

To print the count of the Bytes present in a file, Pass the -c option to wc command.

~$ wc -c months.txt 
115 months.txt

Note: You can also say that the size of this file is 115 bytes.

You can also use the long option --bytes.

~$ wc --bytes months.txt

Read Complete Article Here

推荐:
35 ls Command Examples in Linux (The Complete Guide)

Do you know how to list contents (files/directories) in Linux? It’s straightforward. In this article…

Head Command Examples in Linux (The Complete Guide)

Linux has several commands that helps to display the contents of a file. such as: cat command nl com…

Linux Shutdown Command Examples (Complete Guide)

Do you know How to shutdown your Linux Operating System securely? It’s straightforward. In this guid…

发表评论

电子邮件地址不会被公开。 必填项已用*标注