Linux Common commands: WC command

Source: Internet
Author: User

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

1. Command format:

WC [Options] File ...

2. Command function:

Counts the number of bytes, words, and lines in the specified file, and displays the output of the statistics. This command counts the number of bytes, word count, and number of lines in the specified file. If the file name is not given, it is read from the standard input. The WC also gives the president count of the files specified.

3. Command parameters:

-C Count bytes.

-L counts the number of rows.

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

-W count words. A word is defined as a string separated by a blank, a jump, or a newline character.

-L Prints the length of the longest line.

-HELP Display Help information

--version displaying version information

4. Usage examples:

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

Command:

WC test.txt

Output:

[Email protected] test]#Cattest.txt hnlinuxpeida.cnblogs.comubuntuubuntu linuxredhatredhatlinuxmint[[email protected] test]#WCTest.txt7  8  -Test.txt[[email protected] test]#WC-l Test.txt7Test.txt[[email protected] test]#WC-C Test.txt -Test.txt[[email protected] test]#WC-WTest.txt8Test.txt[[email protected] test]#WC-m Test.txt -Test.txt[[email protected] test]#WC-L test.txt -Test.txt

Description

7 8 Test.txt

Number of Rows Word count bytes file name

Example 2: How to do a WC command to print only statistics do not print file names

Command:

Output:

WC -7cat test.txt | WC -l7[[email protected] test]#

Description

Using 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:

[[Email protected] test]# CD Test6[[email protected] test6]# ll Total604---xr--r--1Root Mail302108  One- -  ,: theLinklog.log---xr--r--1Mail users302108  One- -  ,: theLog2012.log-rw-r--r--1Mail users A  One- -  ,: theLog2013.log-rw-r--r--1Root Mail0  One- -  ,: theLog2014.log-rw-r--r--1Root Mail0  One- -  ,: theLog2015.log-rw-r--r--1Root Mail0  One- -  ,: theLog2016.log-rw-r--r--1Root Mail0  One- -  ,: theLog2017.log[[email protected] test6]#ls-L |WC-L8[email protected] test6]#

Description

The number contains the current directory

Linux Common commands: WC command

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.