Linux命令學習(33) wc命令

來源:互聯網
上載者:User

標籤:blog   http   io   ar   os   使用   sp   檔案   div   

Linux系統中的wc(Word Count)命令的功能為統計指定檔案中的位元組數、字數、行數,並將統計結果顯示輸出。

1.命令格式:

wc [選項]檔案...

2.命令功能:

統計指定檔案中的位元組數、字數、行數,並將統計結果顯示輸出。該命令統計指定檔案中的位元組數、字數、行數。如果沒有給出檔案名稱,則從標準輸入讀取。wc同時也給出所指定檔案的總統計數。

3.命令參數:

-c 統計位元組數。

-l 統計行數。

-m 統計字元數。這個標誌不能與 -c 標誌一起使用。

-w 統計字數。一個字被定義為由空白、跳格或換行字元分隔的字串。

-L 列印最長行的長度。

-help 顯示協助資訊

--version 顯示版本資訊

4.使用執行個體:

執行個體1:查看檔案的位元組數、字數、行數

命令:

wc test.txt

輸出:

[[email protected] test]# cat test.txt 

hnlinux

peida.cnblogs.com

ubuntu

ubuntu linux

redhat

Redhat

linuxmint

[[email protected] test]# wc test.txt

 7  8 70 test.txt

[[email protected] test]# wc -l test.txt 

7 test.txt

[[email protected] test]# wc -c test.txt 

70 test.txt

[[email protected] test]# wc -w test.txt 

8 test.txt

[[email protected] test]# wc -m test.txt 

70 test.txt

[[email protected] test]# wc -L test.txt 

17 test.txt

 

說明:

7     8     70     test.txt

行數 單詞數 位元組數 檔案名稱

 

執行個體2:用wc命令怎麼做到只列印統計數字不列印檔案名

命令:

輸出:

[[email protected]calhost test]# wc -l test.txt 

7 test.txt

[[email protected] test]# cat test.txt |wc -l

7[[email protected] test]#

說明:

使用管道線,這在編寫shell指令碼時特別有用。

 

執行個體3:用來統計目前的目錄下的檔案數

命令:

ls -l | wc -l

輸出:

[[email protected] test]# cd test6

[[email protected] 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

[[email protected] test6]# ls -l | wc -l

8

[[email protected] test6]#

  • 相關文章推薦:
  • linux命令執行個體教程之wc命令
  • wc命令應用舉例
  • 本文來自:愛好Linux技術網
  • 本文連結:http://www.ahlinux.com/start/cmd/9062.html

Linux命令學習(33) wc命令

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.