Common Linux commands (12th)-wc
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 function:
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.Instance used:
Instance 1:View the number of bytes, number of words, and number of lines of a file
Command: wc test.txt
Note:
7 8 70 test.txt
Number of rows, number of words, number of bytes, file name
[root@localhost test]# cat test.txt hnlinuxpeida.cnblogs.comubuntuubuntu linuxredhatRedhatlinuxmint[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
Example 2:How to Use the wc command to print only the statistics and not the file name
Command: wc-l test.txt
Note: Use MPs queue, which is particularly useful when writing shell scripts.
[root@localhost test]# wc -l test.txt 7 test.txt[root@localhost test]# cat test.txt |wc -l7[root@localhost test]#
Example 3:Used to count the number of files in the current directory
Command: ls-l | wc-l
Note: The quantity contains the current directory.
[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-l8 [root @ localhost test6] #