国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Linux > 正文

linux命令大全之wc命令詳解(統(tǒng)計文件字節(jié)數(shù))

2020-07-10 11:45:21
字體:
來源:轉載
供稿:網(wǎng)友

Linux系統(tǒng)中的wc(Word Count)命令的功能為統(tǒng)計指定文件中的字節(jié)數(shù)、字數(shù)、行數(shù),并將統(tǒng)計結果顯示輸出。

1.命令格式:
wc [選項]文件...

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

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

4.使用實例:
實例1:查看文件的字節(jié)數(shù)、字數(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ù)   文件名


實例2:用wc命令怎么做到只打印統(tǒng)計數(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腳本時特別有用。

實例3:用來統(tǒng)計當前目錄下的文件數(shù)
命令: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]#

說明:
數(shù)量中包含當前目錄

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 大余县| 原平市| 阆中市| 安达市| 许昌市| 望奎县| 惠安县| 丹巴县| 务川| 中牟县| 兴文县| 宝丰县| 丹东市| 微博| 新疆| 罗田县| 固镇县| 台东市| 新邵县| 响水县| 衡南县| 墨玉县| 韩城市| 泾源县| 环江| 广平县| 广宗县| 彭州市| 图们市| 沂南县| 大洼县| 平凉市| 乐业县| 阳城县| 镇坪县| 太仆寺旗| 西贡区| 宁化县| 滁州市| 金华市| 石景山区|