導航:首頁 > 編程系統 > linux命令wc

linux命令wc

發布時間:2024-11-12 08:05:39

linux 常用命令 wc

wc 用於統計文件中的信息,包括位元組數、字數、行數,以及文件數量。

使用方法:wc [選項] 文件名。

不帶參數時,顯示全部信息:

命令:wc 文件名。

示例:統計 test.txt 的行數、單詞數和位元組數,並輸出文件名。

命令:wc test.txt。

等同於:wc -lwc test.txt。

統計文件行數:

命令:wc -l 文件名。

示例:統計 test.txt 的行數並輸出文件名。

命令:wc -l test.txt。

統計文件單詞數:

命令:wc -w 文件名。

示例:統計 test.txt 的單詞數並輸出文件名。

命令:wc -w test.txt。

統計文件位元組數:

命令:wc -c 文件名。

示例:統計 test.txt 的位元組數並輸出文件名。

命令:wc -c test.txt。

統計文件字元數:

命令:wc -m 文件名。

示例:統計 test.txt 的字元數並輸出文件名。

注意:不能與 -c 選項同時使用。

統計最長行長度:

命令:wc -L 文件名。

示例:列印 test.txt 最長行的長度。

命令:wc -L test.txt。

與其他命令結合使用:

使用管道功能,如與 cat 結合統計行數。

命令:cat -n test.txt。

示例:查看 test.txt 內容並輸出行號。

命令:cat test.txt | wc -l。

與 ls 結合統計文件數量:

命令:ls | wc -l。

總結:wc 命令是 Linux 中強大的文件統計工具,掌握其使用能提高工作效率。後續將分享更多 Linux 命令的使用技巧。

② linux命令大全之wc命令詳解

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命令怎麼做到只列印統計數字不列印文件名
  命令: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:用來統計當前目錄下的文件數
  命令: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相關的資料

熱點內容
awr導出cad文件 瀏覽:925
參公文件去哪裡找 瀏覽:827
excel表批量日期設置成文件夾存放 瀏覽:90
如何把資料庫加入其中 瀏覽:661
編程除法怎麼取消取整 瀏覽:625
股票編程軟體哪裡有賣 瀏覽:503
access導入多個txt文件 瀏覽:917
大臉app安卓下載 瀏覽:439
怎麼休改文件名 瀏覽:989
cdr導出圖片不顯示文件名 瀏覽:761
pcdmis如何離線編程 瀏覽:201
微信推文插入文件 瀏覽:844
生產文件櫃圖片 瀏覽:244
如何設置微信數據增加 瀏覽:95
excel文件不再增大 瀏覽:613
ug編程刀路怎麼復制不用滑鼠選取 瀏覽:97
excel文件打開擴展名錯誤 瀏覽:10
阿里巴巴怎麼做數據包 瀏覽:442
無線網路連接一直顯示未連接 瀏覽:25
windows7如何自動激活工具下載 瀏覽:57

友情鏈接