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 CountsByte CountsCharacter CountsNewline CountsMaximum 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 ###JanuaryFebruaryMarchAprilMayJuneJulyAugustSeptemberOctoberNovemberDecember

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

Word CountsByte CountsCharacter CountsLine 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


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章