iT邦幫忙

0

9 wc Command Examples in Linux (Complete Guide)

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


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言