Linux wc命令用於計算字數。oop
利用wc指令咱們能夠計算文件的Byte數、字數、或是列數,若不指定文件名稱、或是所給予的文件名爲"-",則wc指令會從標準輸入設備讀取數據。spa
語法 wc [-clw][--help][--version][文件...]code
參數 blog
實例1hadoop
在默認的狀況下,wc將計算指定文件的行數、字數,以及字節數。io
使用的命令爲:class
wc testfile test
$ wc testfile # testfile文件的統計信息 3 92 598 testfile # testfile文件的行數爲三、單詞數9二、字節數598
其中,3 個數字分別表示testfile文件的行數、單詞數,以及該文件的字節數。file
若是想同時統計多個文件的信息,例如同時統計testfile、testfile_一、testfile_2,可以使用以下命令:語法
$ wc testfile testfile_1 testfile_2 #統計三個文件的信息 3 92 598 testfile #第一個文件行數爲三、單詞數9二、字節數598 9 18 78 testfile_1 #第二個文件的行數爲九、單詞數1八、字節數78 3 6 32 testfile_2 #第三個文件的行數爲三、單詞數六、字節數32 15 116 708 總用量 #三個文件總共的行數爲1五、單詞數11六、字節數708
實例2
查看文件的字節數、字數、行數:
[hadoop@hadoop000 data]$ cat data.txt hello world welcome hello hello welcome [hadoop@hadoop000 data]$ wc data.txt 2 6 40 data.txt [hadoop@hadoop000 data]$ wc -l data.txt 2 data.txt [hadoop@hadoop000 data]$ wc -c data.txt 40 data.txt [hadoop@hadoop000 data]$ wc -w data.txt 6 data.txt
實例3
用wc命令怎麼作到只打印統計數字不打印文件名:使用管道線
[hadoop@hadoop000 data]$ wc -l data.txt 2 data.txt [hadoop@hadoop000 data]$ cat data.txt |wc -l 2
實例4
統計當前目錄下的文件數:ls -l | wc -l (數量中包含當前目錄)
[hadoop@hadoop000 data]$ ll total 206024
-rwxr-xr-x 1 hadoop hadoop 2334 Nov 25 04:36 access.log -rw-rw-r-- 1 hadoop hadoop 40 Nov 25 04:26 data.txt -rw-r----- 1 hadoop hadoop 79 Nov 25 23:03 dept.txt -rw-r----- 1 hadoop hadoop 700 Nov 25 22:05 emp.txt -rw-r----- 1 hadoop hadoop 700 Dec 9 08:40 emp.txt-bak -rw-rw-r-- 1 hadoop hadoop 27 Nov 25 21:41 helloworld.txt -rw-rw-r-- 1 hadoop hadoop 34 Oct 21 2018 h.txt -rw-r--r-- 1 hadoop hadoop 37381906 Dec 9 08:55 part-r-00000 [hadoop@hadoop000 data]$ ls -l |wc -l 9