文章目錄
- 1. wc 命令說明
- 2. wc 命令語法
- 3. wc 命令示例
- 3.1 不加參數
- 3.2 -c(統計字節數)
- 3.3 -m(統計字符數)
- 3.4 -l(統計行數)
- 3.5 -L(最長一行的長度)
- 3.6 -w(統計單詞數)
- 4. 總結
1. wc 命令說明
wc(word count):可以計算文件的Byte數、字符數、或是列數,基本信息如下:
Usage: wc [OPTION]... [FILE]...or: wc [OPTION]... --files0-from=F
Print newline, word, and byte counts for each FILE, and a total line if
more than one FILE is specified. With no FILE, or when FILE is -,
read standard input.-c, --bytes print the byte counts-m, --chars print the character counts-l, --lines print the newline counts--files0-from=F read input from the files specified byNUL-terminated names in file F;If F is - then read names from standard input-L, --max-line-length print the length of the longest line-w, --words print the word counts--help display this help and exit--version output version information and exitReport wc bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'wc invocation'
參數如下:
選項 | 作用 |
---|---|
-c | 統計字節數 |
-m | 統計字符數 |
-l | 統計行數 |
-L | 統計最長行的長度 |
-w | 統計單詞數 |
2. wc 命令語法
wc [選項] 文件名
3. wc 命令示例
3.1 不加參數
此時,會展示出文件的行數、單詞數、字節數
wc 文件名
3.2 -c(統計字節數)
-c:統計字節數,空格、換行符也算
wc -c 文件名
3.3 -m(統計字符數)
-m:統計字符數,空格、換行符也算
wc -m 文件名
3.4 -l(統計行數)
-l:統計行數,沒啥說的,有幾行就是幾行
wc -l 文件名
3.5 -L(最長一行的長度)
-L:統計最長一行的長度,不算換行符。但是有個疑問,英文1個字母是一個長度,1個中文卻是2個長度,但是我系統的字符集是 utf-8 ,查了一些資料也沒找到原因,有知道的大神告訴我一下,感謝。
wc -L 文件名
3.6 -w(統計單詞數)
-w:統計單詞數,由空格或者換行符隔開才算一個單詞
wc -w 文件名
4. 總結
wc 統計文件字節、字符、行數等信息。某些時候,腳本里面會用的
wc -l
去統計結果。