Linux系統(tǒng)中的wc(Word Count)命令的功能為統(tǒng)計(jì)指定文件中的字節(jié)數(shù)、字?jǐn)?shù)、行數(shù)linux命令大全,并將統(tǒng)計(jì)結(jié)果顯示輸出。
1.命令格式:
wc[選項(xiàng)]文件...
2.命令功能:
統(tǒng)計(jì)指定文件中的字節(jié)數(shù)、字?jǐn)?shù)、行數(shù)linux命令大全,并將統(tǒng)計(jì)結(jié)果顯示輸出。該命令統(tǒng)計(jì)指定文件中的字節(jié)數(shù)、字?jǐn)?shù)、行數(shù)。如果沒(méi)有給出文件名,則從標(biāo)準(zhǔn)輸入讀取。wc同時(shí)也給出所指定文件的總統(tǒng)計(jì)數(shù)。
3.命令參數(shù):
-c統(tǒng)計(jì)字節(jié)數(shù)。
-l統(tǒng)計(jì)行數(shù)。
-m統(tǒng)計(jì)字符數(shù)。這個(gè)標(biāo)志不能與-c標(biāo)志一起使用。
-w統(tǒng)計(jì)字?jǐn)?shù)。一個(gè)字被定義為由空白、跳格或換行字符分隔的字符串。
-L打印最長(zhǎng)行的長(zhǎng)度。
-help顯示幫助信息
--version顯示版本信息
4.使用實(shí)例:
實(shí)例1:查看文件的字節(jié)數(shù)、字?jǐn)?shù)、行數(shù)
命令:
wctest.txt
輸出:
[root@localhosttest]#cattest.txt
hnlinux
peida.cnblogs.com
ubuntu
ubuntulinux
redhat
Redhat
linuxmint
[root@localhosttest]#wctest.txt
7870test.txt
[root@localhosttest]#wc-ltest.txt
7test.txt
[root@localhosttest]#wc-ctest.txt
70test.txt
[root@localhosttest]#wc-wtest.txt
8test.txt
[root@localhosttest]#wc-mtest.txt
70test.txt
[root@localhosttest]#wc-Ltest.txt
17test.txt
說(shuō)明:
7870test.txt
行數(shù)單詞數(shù)字節(jié)數(shù)文件名
實(shí)例2:用wc命令怎么做到只打印統(tǒng)計(jì)數(shù)字不打印文件名
命令:
輸出:
[root@localhosttest]#wc-ltest.txt
7test.txt
[root@localhosttest]#cattest.txt|wc-l
7[root@localhosttest]#
說(shuō)明:
使用管道線,這在編寫shell腳本時(shí)特別有用。
實(shí)例3:用來(lái)統(tǒng)計(jì)當(dāng)前目錄下的文件數(shù)
命令:
ls-l|wc-l
輸出:
[root@localhosttest]#cdtest6
[root@localhosttest6]#ll
總計(jì)604
---xr--r--1rootmail30210811-3008:39linklog.log
---xr--r--1mailusers30210811-3008:39log2012.log
-rw-r--r--1mailusers6111-3008:39log2013.log
-rw-r--r--1rootmail011-3008:39log2014.log
-rw-r--r--1rootmail011-3008:39log2015.log
-rw-r--r--1rootmail011-3008:39log2016.log
-rw-r--r--1rootmail011-3008:39log2017.log
[root@localhosttest6]#ls-l|wc-l
8
[root@localhosttest6]#
說(shuō)明:
數(shù)量中包含當(dāng)前目錄