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]# cat Test.txt
Hnlinux
Peida.cnblogs.com
Ubuntu
Ubuntu Linux
Redhat
Redhat
LinuxMint
[Email protected] test]# WC test.txt
7 8 Test.txt
[Email protected] test]# wc-l test.txt
7 Test.txt
[Email protected] test]# wc-c test.txt
Test.txt
[Email protected] test]# wc-w test.txt
8 Test.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:
[Email protected] test]# wc-l test.txt
7 Test.txt
[email protected] test]# cat Test.txt |wc-l
7[[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
Total 604
---xr--r--1 root mail 302108 11-30 08:39 linklog.log
---xr--r--1 mail users 302108 11-30 08:39 log2012.log
-rw-r--r--1 Mail users 11-30 08:39 log2013.log
-rw-r--r--1 root mail 0 11-30 08:39 log2014.log
-rw-r--r--1 root mail 0 11-30 08:39 log2015.log
-rw-r--r--1 root mail 0 11-30 08:39 log2016.log
-rw-r--r--1 root mail 0 11-30 08:39 log2017.log
[Email protected] test6]# Ls-l | Wc-l
8
[Email protected] test6]#
Description
The number contains the current directory
Shell's WC Command statistics