Linux命令篇 - wc 命令

wc

wc - print newline, word, and byte counts for each file

wc: 統計文件的字節數字數行數

格式: wc [OPTION]... [FILE]...

常用參數:

OPTION 意義
-w 統計字數,或--words:只顯示字數。一個字被定義爲由空白、跳格或換行字符分隔的字符串
-c 統計字節數,或--bytes或--chars:只顯示Bytes數
-l 統計行數,或--lines:只顯示列數
-m 統計字符數
-L 打印最長行的長度
--help 顯示幫助信息
--version 顯示版本信息

參考示例:

  • 統計字數
# 創建 test.out 文件
$ vi test.out
hello world
hello world
hello world
hello world hello world

# 查看 test.out 文件
$ cat test.out 
hello world
hello world
hello world
hello world hello world
$ wc -w test.out
10 test.txt
  • 統計字節數
$ wc -c test.out 
60 test.txt
  • 統計字符數
$ wc -m test.out 
60 test.txt
  • 統計單詞數
$ wc -w test.out
10 test.out
  • 統計行數單詞數字節數
$ wc test.out   //等價於 wc -lwc test.out
4 10 60 test.out
  • 統計行數
$ wc -l test.out 
4 test.out
  • 打印最長行的長度
$ wc -L test.out 
23 test.out
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章