導航:首頁 > 編程系統 > 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相關的資料

熱點內容
餘姚數控編程培訓哪裡專業 瀏覽:419
qq空間66版本下載 瀏覽:908
有一款看美劇的app是什麼 瀏覽:397
前端後端json資料庫 瀏覽:267
vi文件格式linux 瀏覽:963
php如何引用js文件 瀏覽:531
word轉成pdf怎麼設置漸變色背景 瀏覽:655
數控車床車刀如何編程 瀏覽:577
為什麼復制到u盤沒有文件 瀏覽:792
三星怎麼設置文件的打開方式 瀏覽:332
微信怎麼發大容量的文件夾 瀏覽:130
hl線切割編程怎麼旋轉圖形 瀏覽:234
qq頭像露全身 瀏覽:811
力量運動員影響哪些體檢數據 瀏覽:176
金山哪裡有加工中心編程培訓學校 瀏覽:113
壓縮文件正在壓縮怎麼取消 瀏覽:462
excel中添加文件路徑名 瀏覽:16
手機收銀用哪個app 瀏覽:229
qq非主流圖片女生帶字 瀏覽:849
移動端js地圖 瀏覽:570

友情鏈接