常用命令之wc

2021-08-28 23:19:34 字數 1951 閱讀 4350

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

1.命令格式:

wc [選項]檔案...

2.命令功能:

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

3.命令引數:

-c 統計位元組數。

-l 統計行數。

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

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

-l 列印最長行的長度。

-help 顯示幫助資訊

--version 顯示版本資訊

4.使用例項:

例項1:檢視檔案的位元組數、字數、行數

命令:wc test.txt

輸出:[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 

7 test.txt

[root@localhost test]# wc -c test.txt 

70 test.txt

[root@localhost test]# wc -w test.txt 

8 test.txt

[root@localhost test]# wc -m test.txt 

70 test.txt

[root@localhost test]# wc -l test.txt 

17 test.txt

說明:7     8     70     test.txt

行數 單詞數 位元組數 檔名

例項2:用wc命令怎麼做到只列印統計數字不列印檔案名

命令:輸出:

[root@localhost test]# wc -l test.txt 

7 test.txt

[root@localhost test]# cat test.txt |wc -l

7說明:

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

例項3:用來統計當前目錄下的檔案數

命令:ls -l | wc -l

輸出:[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常用命令之管道 wc

8 管道命令 豎線符號代表的就是管道符 管道是一種兩個程序間進行單向通訊的機制。因為管道傳遞資料的單向性,所以又稱為半雙工管道。介紹 缺點 資料只能從乙個程序流向另乙個程序 其中乙個讀管道,乙個寫管道 如果要進行雙工通訊,需要建立兩個管道。管道只能用於父子程序或兄弟程序間通訊,也就是說管道只能用於具...

linux常用命令 wc

linux系統中的wc word count 命令的功能為統計指定檔案中的位元組數 字數 行數,並將統計結果顯示輸出 37 代表了檔案總共有37行,主機如果檔案中有空行,也會被計數 59 代表了有多少個單詞,這裡裡邊所說的單詞,並非是英語自定裡邊所說的單詞,比如afaf,dfdf,erefdfdf ...

Linux常用命令 wc命令

linux系統中的wc word count 命令的功能為統計指定檔案中的位元組數 字數 行數,並將統計結果顯示輸出。1 命令格式 wc 選項 檔案.2 命令功能 統計指定檔案中的位元組數 字數 行數,並將統計結果顯示輸出。該命令統計指定檔案中的位元組數 字數 行數。如果沒有給出檔名,則從標準輸入讀...