Go Linux command (max): 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.

Original: http://blog.jobbole.com/109925/

http://blog.csdn.net/jerry_1126/article/details/52107947------Diagram

1. Command format:

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

Shell
12345678910111213 -C count bytes. -L COUNT the number of rows. -m counts 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 separated by a blank, a jump, or a newline character. -L Print the length of the longest line. -help Display assistance - -version displays release information

4. Usage examples:

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

Command:

Shell
1 WC test.txt

Output:

Shell
123456789101112131415161718192021222324252627282930313233343536373839 [root@localhost test]# cat test.txt HnlinuxPeida. cnblogs. com Ubuntuubuntu Linux RedhatRedhatLinuxMint[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

Shell
123 7 8 test.txt number of lines Word count bytes file name

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

Command:

Output:

Shell
1 [root@localhost test]# wc-l test.txt

7 Test.txt

Shell
123 [root@localhost test]# cat test.txt |wc-l 7[root@localhost 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:

Shell
1 LS -l | WC -l

Output:

Shell
12345678910111213141516171819202122232425 [root@localhost test]# cd Test6 [root@localhost test6]# ll Total604--- XR--R-- 1 root mail 302108 - : linklog. Log --- XR--R-- 1 mail users 302108 - :39 log2012. Log -RW-R--R-- 1 mail users -- £ º log2013 . Log -RW-R--R-- 1 root mail 0 -from : log2014 . Log -RW-R--R-- 1 root mail 0 -from : log2015 . Log -RW-R--R-- 1 root mail 0 -from : log2016 . Log -RW-R--R-- 1 root mail 0 -from : log2017 . Log [root@localhost test6]# ls-l | wc-l 8[root@localhost test6]#

Description

The number contains the current directory

Go Linux command (max): WC command

Related Article

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.