linux系統中的wc(Word Count)命令的功能為統計指定文件中的字節數、字數、行數,并將統計結果顯示輸出。
統計指定文件中的字節數、字數、行數,并將統計結果顯示輸出。該命令統計指定文件中的字節數、字數、行數。如果沒有給出文件名,則從標準輸入讀取。wc同時也給出所指定文件的總統計數。
實例1:查看文件的字節數、字數、行數 命令:
wc test.txt輸出:
[root@localhost test]# cat test.txt hnlinuxpeida.CUOXin.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說明:
7 8 70 test.txt 行數 單詞數 字節數 文件名
實例2:用wc命令怎么做到只打印統計數字不打印文件名 命令: 輸出:
[root@localhost test]# wc -l test.txt 7 test.txt[root@localhost test]# cat test.txt |wc -l7[root@localhost test]#說明:
使用管道線,這在編寫shell腳本時特別有用。
實例3:用來統計當前目錄下的文件數 命令:
ls -l | wc -l輸出:
[root@localhost test]# cd test6[root@localhost test6]# ll總計 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 61 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[root@localhost test6]# ls -l | wc -l8[root@localhost test6]#說明:
數量中包含當前目錄
新聞熱點
疑難解答