如何在linux中使用wc命令

今天就跟大家聊聊有關(guān)如何在linux中使用wc命令,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

創(chuàng)新互聯(lián)長期為成百上千客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為清水河企業(yè)提供專業(yè)的成都網(wǎng)站建設(shè)、成都網(wǎng)站制作,清水河網(wǎng)站改版等技術(shù)服務(wù)。擁有10余年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。

1.命令格式:

wc [選項(xiàng)]文件...

2.命令功能:
統(tǒng)計(jì)指定文件中的字節(jié)數(shù)、字?jǐn)?shù)、行數(shù),并將統(tǒng)計(jì)結(jié)果顯示輸出。該命令統(tǒng)計(jì)指定文件中的字節(jié)數(shù)、字?jǐn)?shù)、行數(shù)。如果沒有給出文件名,則從標(biāo)準(zhǔn)輸入讀取。wc同時(shí)也給出所指定文件的總統(tǒng)計(jì)數(shù)。

3.命令參數(shù):
-c 統(tǒng)計(jì)字節(jié)數(shù)。
-l 統(tǒng)計(jì)行數(shù)。
-m 統(tǒng)計(jì)字符數(shù)。這個(gè)標(biāo)志不能與 -c 標(biāo)志一起使用。
-w 統(tǒng)計(jì)字?jǐn)?shù)。一個(gè)字被定義為由空白、跳格或換行字符分隔的字符串。
-L 打印最長行的長度。
-help 顯示幫助信息
--version 顯示版本信息

4.使用實(shí)例:
實(shí)例1:查看文件的字節(jié)數(shù)、字?jǐn)?shù)、行數(shù)
命令: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
行數(shù)   單詞數(shù)  字節(jié)數(shù)   文件名


實(shí)例2:用wc命令怎么做到只打印統(tǒng)計(jì)數(shù)字不打印文件名
命令:wc -l test.txt
輸出:

代碼如下:


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


說明:
使用管道線,這在編寫shell腳本時(shí)特別有用。

實(shí)例3:用來統(tǒng)計(jì)當(dāng)前目錄下的文件數(shù)
命令:ls -l | wc -l
輸出:

代碼如下:


[root@localhost test]# cd test6
[root@localhost test6]# ll
總計(jì) 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]#

看完上述內(nèi)容,你們對如何在linux中使用wc命令有進(jìn)一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。

當(dāng)前標(biāo)題:如何在linux中使用wc命令
URL地址:http://muchs.cn/article22/ppjijc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站ChatGPT、網(wǎng)站排名、虛擬主機(jī)品牌網(wǎng)站制作、手機(jī)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設(shè)