Detailed explanation of wc commands in linux commands (statistics on the number of file bytes)

Source: Internet
Author: User
The wc (WordCount) command in Linux is used to count the number of bytes, number of words, and number of rows in a specified file, and the statistical results are displayed and output.

In Linux, the wc (Word Count) command is used to Count the number of bytes, number of words, and number of lines in a specified file, and display the statistical results.

1. command format:
Wc [option] file...

2. command functions:
Counts the number of bytes, number of words, and number of rows in a specified file, and displays the statistical results. This command counts the number of bytes, number of words, and number of lines in a specified file. If no file name is provided, it is read from the standard input. Wc also provides the presidential count of the specified file.

3. command parameters:
-C: counts the number of bytes.
-L number of statistics rows.
-M: The number of characters. This flag cannot be used with the-c flag.
-W counts the number of words. A character is defined as a string separated by blank, skip, or line breaks.
-L print the maximum length of a row.
-Help: displays help information.
-- Version: displays version information.

4. example:
Instance 1: view the number of bytes, number of words, and number of lines of a file
Command: wc test.txt
Output:

Copy codeThe code is as follows:
[Root @ localhost test] # cat test.txt
Hnlinux
Peida.cnblogs.com
Ubuntu
Ubuntu linux
Redhat
Redhat
Linuxmint
[Root @ localhost test] # wc test.txt
7 8 70 test.txt
[Root @ localhost test] # wc-l test.txt
7 test.txt
[Root @ localhost test] # wc-c test.txt
70 test.txt
[Root @ localhost test] # wc-w test.txt
8 test.txt
[Root @ localhost test] # wc-m test.txt
70 test.txt
[Root @ localhost test] # wc-L test.txt
17 test.txt

Note:
7 8 70 test.txt
Number of rows, number of words, number of bytes, file name


Example 2: how to use the wc command to print only statistics and not file names
Command: wc-l test.txt
Output:

Copy codeThe code is as follows:
[Root @ localhost test] # wc-l test.txt
7 test.txt
[Root @ localhost test] # cat test.txt | wc-l
7 [root @ localhost test] #

Note:
Use MPs queue, which is particularly useful when writing shell scripts.

Instance 3: used to count the number of files in the current directory
Command: ls-l | wc-l
Output:

Copy codeThe code is as follows:
[Root @ localhost test] # cd test6
[Root @ localhost test6] # ll
Total 604
--- Xr -- r -- 1 root mail 302108 11-30 linklog. log
--- Xr -- r -- 1 mail users 302108 11-30 log2012.log
-Rw-r -- 1 mail users 61 11-30 08:39 log2013.log
-Rw-r -- 1 root mail 0 11-30 08:39 log2014.log
-Rw-r -- 1 root mail 0 11-30 08:39 log2015.log
-Rw-r -- 1 root mail 0 11-30 08:39 log2016.log
-Rw-r -- 1 root mail 0 11-30 08:39 log2017.log
[Root @ localhost test6] # ls-l | wc-l
8
[Root @ localhost test6] #

Note:
The quantity contains the current directory.

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.