技术原理

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

微信扫一扫,分享到朋友圈

9 wc Command Examples in Linux (Complete Guide)
0 0

你也可能喜欢

发表评论

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

提示:点击验证后方可评论!

插入图片
人工智能就业前景分析 投稿者
我还没有学会写个人说明!
最近文章
  • * 没有更多文章了
  • 广告位

    热门搜索

    分类目录