Linux系統(tǒng)中的wc(表示:Word Count,不是指廁所)命令的功能為統(tǒng)計(jì)指定文件中的字節(jié)數(shù)、字?jǐn)?shù)、行數(shù),并將統(tǒng)計(jì)結(jié)果顯示輸出。
wc [選項(xiàng)]文件…
統(tǒng)計(jì)指定文件中的字節(jié)數(shù)、字?jǐn)?shù)、行數(shù),并將統(tǒng)計(jì)結(jié)果顯示輸出。該命令統(tǒng)計(jì)指定文件中的字節(jié)數(shù)、字?jǐn)?shù)、行數(shù)。如果沒有給出文件名,則從標(biāo)準(zhǔn)輸入讀取。wc
同時(shí)也給出所指定文件的總統(tǒng)計(jì)數(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)度。-hel
p 顯示幫助信息--version
顯示版本信息命令:
wc file2.txt
輸出:
[yiibai@localhost ~]$ cat file2.txt
windows 10
windows 7
linux
C#
java
PHP
python
1003
Hello Word.
[yiibai@localhost ~]$ wc file2.txt
9 12 63 file2.txt
[yiibai@localhost ~]$
說明:
9 12 63 file2.txt
行數(shù) 單詞數(shù) 字節(jié)數(shù) 文件名
命令執(zhí)行和輸出:
[yiibai@localhost ~]$ wc -l file2.txt
9 file2.txt
[yiibai@localhost ~]$ cat file2.txt |wc -l
9
[yiibai@localhost ~]$
說明:使用管道線,這在編寫shell腳本時(shí)特別有用。
命令:
ls -l | wc -l
輸出:
[yiibai@localhost ~]$ ls -l | wc -l
11
[yiibai@localhost ~]$ ls
file1.txt file2.txt logs newlog.log patch.txt project run.py scripts test4 test5
[yiibai@localhost ~]$
說明:數(shù)量中包含當(dāng)前目錄