(轉)Linux 命令(40): wc 命令
阿新 • • 發佈:2018-01-14
不能 數字 實例 .net rip nta host com 標準
Shell
Linux系統中的wc(Word Count)命令的功能為統計指定文件中的字節數、字數、行數,並將統計結果顯示輸出。
原文:http://blog.jobbole.com/109925/
http://blog.csdn.net/jerry_1126/article/details/52107947------圖解
1.命令格式:
1 | wc [選項]文件... |
2.命令功能:
統計指定文件中的字節數、字數、行數,並將統計結果顯示輸出。該命令統計指定文件中的字節數、字數、行數。如果沒有給出文件名,則從標準輸入讀取。wc同時也給出所指定文件的總統計數。
3.命令參數:
1 2 3 4 5 6 7 8 9 10 11 12 13 | -c 統計字節數。 -l 統計行數。 -m 統計字符數。這個標誌不能與 -c 標誌一起使用。 -w 統計字數。一個字被定義為由空白、跳格或換行字符分隔的字符串。 -L 打印最長行的長度。 -help 顯示幫助信息 --version 顯示版本信息 |
4.使用實例:
實例1:查看文件的字節數、字數、行數
命令:
Shell1 | wc test.txt |
輸出:
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
[root@localhost test]# cat test.txt
hnlinux
peida.cnblogs.com
ubuntu
ubuntu linux
redhat
Redhat
linuxmint
[root@localhost test]# wc test.txt
7 8 70 test.txt
[root@localhost test]# wc -l test.txt |
說明:
Shell
1 2 3 | 7 8 70 test.txt 行數 單詞數 字節數 文件名 |
實例2:用wc命令怎麽做到只打印統計數字不打印文件名
命令:
輸出:
Shell1 | [root@localhost test]# wc -l test.txt |
7 test.txt
Shell
1 2 3 | [root@localhost test]# cat test.txt |wc -l 7[root@localhost test]# |
說明:
使用管道線,這在編寫shell腳本時特別有用。
實例3:用來統計當前目錄下的文件數
命令:
Shell1 | ls -l | wc -l |
輸出:
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | [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 -l 8 [root@localhost test6]# |
說明:
數量中包含當前目錄
(轉)Linux 命令(40): wc 命令