Linux Basic Command (m) WC command

Source: Internet
Author: User
Tags linux

The function of the WC (Word Count) command in a Linux system is to count the number of bytes, words, and rows in the specified file and display the results to the output.

1. Command format:

WC [Options] File ...

2. Command function:

Counts the number of bytes, words, and rows in the specified file and displays the results to the output. This command counts the number of bytes, word count, and number of lines in the specified file. If no file name is given, read from standard input. The WC also gives the president count of the specified documents.

3. Command parameters:

-C counts the number of bytes.

-L counts the number of rows.

-M statistics the number of characters. This flag cannot be used with the-C flag.

-W counts the number of words. A word is defined as a string delimited by a blank, jump, or newline character.

-L Prints the length of the longest line.

-HELP Display Help information

--version Display version Information

4. Use instance:

Instance 1: View the number of bytes, words, lines of a file

Command:

WC test.txt

Output:

[Root@localhost test]# Cat Test.txt

Hnlinux

Peida.cnblogs.com

Ubuntu

Ubuntu Linux

Redhat

Redhat

LinuxMint

[Root@localhost test]# WC test.txt

7 8 Test.txt

[Root@localhost test]# wc-l test.txt

7 Test.txt

[Root@localhost test]# wc-c test.txt

Test.txt

[Root@localhost test]# wc-w test.txt

8 Test.txt

[Root@localhost test]# wc-m test.txt

Test.txt

[Root@localhost test]# wc-l test.txt

Test.txt

Description

7 8 Test.txt

Number of lines of words byte number of file name

Example 2: How to use WC command to print only statistics do not print file name

Command:

Output:

[Root@localhost test]# wc-l test.txt

7 Test.txt

[Root@localhost test]# cat Test.txt |wc-l

7[root@localhost test]#

Description

Use pipe lines, which is especially useful when writing shell scripts.

Example 3: Used to count the number of files in the current directory

Command:

Ls-l | Wc-l

Output:

[Root@localhost test]# CD Test6

[Root@localhost test6]# LL

Total 604

---xr--r--1 root mail 302108 11-30 08:39 linklog.log

---xr--r--1 mail users 302108 11-30 08:39 log2012.log

-rw-r--r--1 Mail users 11-30 08:39 log2013.log

-rw-r--r--1 root mail 0 11-30 08:39 log2014.log

-rw-r--r--1 root mail 0 11-30 08:39 log2015.log

-rw-r--r--1 root mail 0 11-30 08:39 log2016.log

-rw-r--r--1 root mail 0 11-30 08:39 log2017.log

[Root@localhost test6]# ls-l | Wc-l

8

[Root@localhost test6]#

Description

The quantity contains the current directory

See a full set of tutorials: http://www.bianceng.cn/OS/Linux/201301/35075.htm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.