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 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 support information --version display version information
4. Usage examples:
Example 1: View the number of bytes, words, and lines of a file
WC test.txt Statistics Test.txt file
Output:
[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
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
Linux commands-Number of bytes, words, and lines in the statistics file: WC