Detailed explanation of wc commands in CentOS

Source: Internet
Author: User

Detailed explanation of wc commands in CentOS

The content of today is the wc command of centos. This name is very memorable. You know what it is.

The function of this command is also very memorable, and its function is very limited:

Wc-c filename: displays the number of bytes of a file.

Wc-m filename: displays the number of characters in a file.

Wc-l filename: displays the number of lines in a file.

Wc-L filename: displays the length of the longest row in a file.

Wc-w filename: displays the number of words in a file.

[Rocrocket @ rocrocket programming] $ cat program 234 5 Hello [rocrocket @ rocrocket programming] $ wc-c program wc1.txt [rocrocket @ rocrocket programming] $ wc-m program wc1.txt [rocrocket @ rocrocket programming] $ wc-l wc1.txt3 wc1.txt [rocrocket @ rocrocket programming] $ wc-L wc1.txt4 wc1.txt [rocrocket @ rocrocket programming] $ wc-w wc1.txt5 wc1.txt

The line break at the end of each line is also a character, and a space is also a character.

Using UTF-8 encoding, a Chinese character is converted to 3 bytes here, wc-c shows 16, that is, "4 bytes in the first row + 5 bytes in the second row + 7 bytes in the third row" = 4 5 7 = 16.

When the-m option is used, a Chinese character is calculated as a character, which is 4 5 3 = 12.

When-L is used, the length of the longest line is given, and the second line is the longest, with four characters long. (apparently, linefeeds are not included)

-W is used to calculate the number of words. A word is a word, and "34" indicates a word. A "hello" indicates a word, SO 2 2 1 = 5.

The Jack describes the tab character. This symbol is special. When-L is used, the tab character counts as 7 characters (depending on the length of a tab, in my system, a tab is counted as 7 spaces ). when-w is used, the tabs and spaces are both treated as word intervals. when-c is used, a Tab character is only a character.

If you directly execute wc wc1.txt, it will display:

[rocrocket@rocrocket programming]$ wc wc1.txt3  5 16 wc1.txt

The output information is the number of lines, characters, and number of bytes.

Wc command
The wc command is used to count the number of bytes, number of words, and number of lines in a specified file, and display the statistical result.
Syntax: wc [Option] file...
Note: This command counts the number of bytes, number of words, and number of lines in a given file. If no file name is provided,
Read from the standard input. wc also provides the presidential count of all specified files. The word is the largest string separated by space characters.

The options of this command are as follows:

-C: counts the number of bytes.
-L number of statistics rows.
-W counts the number of words.

These options can be used in combination.
The order and number of output columns are not affected by the order and number of options.
It is always displayed in the following order and each item has at most one column.
Number of lines, number of words, number of bytes, and file name
If there is no file name in the command line, no file name appears in the output.

For example:
$ Wc-lcw file1 file2
4 33 file1
7 52 file2
11 11 85 total
Omit any option-lcw. The wc command execution result is the same as above.

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.