Detailed explanation of wc commands in CentOS

Source: Internet
Author: User

Wc [word count]

Name wc-print the number of newlines, words, andbytes (word count)

In files

Syntax wc [option] files

Function Description: counts the number of characters in the number of bytes in a specified file. If no file is specified, it is read from the standard input. This command also counts the total number of specified files.

Command Parameters

-C: count the number of bytes.

-L number of statistics rows

-W counts the number of words. A character string is defined as a string separated by white spaces or line breaks. That is to say, a line break is a word only when a space jump occurs.

-M: The number of characters. It cannot be used together with-c.

-L print the maximum length of a row.

Instance usage

View the number of lines, characters, and bytes of a file

[Root @ LiWenTong ~] # Wc 1.log

6 14 47 1.log

[Root @ LiWenTong ~] # Cat 1.log

1

2

3

4

I belive I can fly

Yes I cando it

[Root @ LiWenTong ~] # Wc-w 1.log

14 1.log

[Root @ LiWenTong ~] # Wc-l 1.log ---> when wc is used to calculate the number of rows, a line break must be added at the end of the file. Otherwise, one fewer wc will occur.

6 1.log

[Root @ LiWenTong ~] # Wc-c 1.log

47 1.log

When wc command is used, only statistical numbers are printed, but file names are not printed.

[Root @ LiWenTong ~] # Wc-w 1.log

14 1.log

[Root @ LiWenTong ~] # Cat 1.log | wc-w

14

Used to count the number of current files

[Root @ LiWenTong ~] # Ls-l | wc-l -- contains 13 files. View the output information first and then make statistics. Wc can also be used for the statistics of many pieces of information after certain processing. The statistical function should be used in many places.

13

[Root @ LiWenTong ~] # Ll

Total 56

-Rwx ------ 1 root 47 Apr 28 :58 1.log

-Rw-r -- 1 root 0 Apr 26 00:18 2.log

-Rw-r -- 1 root 0 Apr 26 00:18 3.log

-Rw ------- 1 root 960 Apr 25 anaconda-ks.cfg

-Rw-r -- 1 root 3692 Apr 25 install. log. syslog

-Rw-r -- 1 root 17 Apr 26 log

Lrwxrwxrwx 1 root 5 Apr 26 00:20 log1-> 1.log

-Rw-r -- 1 root 0 Apr 26 00:18 log2

-Rw-r -- 1 root 20480 Apr 27 :13 13 log.tar

-Rw-r -- 1 root 169 Apr 27 log.tar. bz

-Rw-r -- 1 root 163 Apr 27 log.tar.gz

Drwxr-xr-x 2 root 4096 Apr 26 test

What if I want to count files containing Chinese characters?

[Root @ LiWenTong ~] # Wc-w 1.txt ---> wc uses a blank grid to wrap the line to determine the number of words. Therefore, no matter whether it is Chinese or not, if there is a blank grid line break, the word count will be increased by 1.

3 1.txt

WcThe number of statistical rows

------------------------------- Subsequent self-Summary -----------------------------

Sometimes it is the quickest way to use the wc command to collect statistics on the number of rows in the file or related to the number of rows. In fact, in the previous article, the command about the operation content is actually a command for the Operation content. A statistical command. This command can be used in combination with many commands for displaying content, such as cat grep head tail, to display content or to transmit content.

In fact, the combined mode is to display the content command + content operation command so that we can do a lot of tasks.

Then, it is important to understand the command parameters. What are the functions of an operation command? intercept, select, Count, exclude, delete, move, and so on. In addition, each function has different parameters, such as byte or reverse order.

Of course, there are some operation commands for the system. For example, you can display the IP address, route display, route adding, file, directory, Installation Software Update time, and so on, as long as you want to perform any operations on the system or want to obtain any information. As long as you are familiar with these commands. The command targets the system itself.

The above is my own summary for the sake of understanding the 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.