歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux技術 >> Linux系統中wc命令使用詳解

Linux系統中wc命令使用詳解

日期:2017/8/19 9:45:21   编辑:Linux技術

  Linux系統中wc命令是統計文件文本的字節數等並顯示輸出。下面由學習啦小編為大家整理了linux系統中wc命令使用詳解,希望對大家有幫助!

  Linux系統中wc命令使用詳解

  Linux系統中的wc(Word Count)命令的功能為統計指定文件中的字節數、字數、行數,並將統計結果顯示輸出。

  1.命令格式:

  wc [選項]文件...

  2.命令功能:

  統計指定文件中的字節數、字數、行數,並將統計結果顯示輸出。該命令統計指定文件中的字節數、字數、行數。如果沒有給出文件名,則從標准輸入讀取。wc同時也給出所指定文件的總統計數。

  3.命令參數:

  -c 統計字節數。

  -l 統計行數。

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

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

  -L 打印最長行的長度。

  -help 顯示幫助信息

  --version 顯示版本信息

  Linux系統中wc命令詳解實例

  在默認的情況下,wc將計算指定文件的行數、字數,以及字節數。使用的命令為:

  wc testfile

  先查看testfile文件的內容,可以看到:

  $ cat testfile

  Linux networks are becoming more and more common, but scurity is often an overlooked

  issue. Unfortunately, in today’s environment all networks are potential hacker targets,

  fro0m tp-secret military research networks to small home LANs.

  Linux Network Securty focuses on securing Linux in a networked environment, where the

  security of the entire network needs to be considered rather than just isolated machines.

  It uses a mix of theory and practicl techniques to teach administrators how to install and

  use security applications, as well as how the applcations work and why they are necesary.

  使用 wc統計,結果如下:

  $ wc testfile # testfile文件的統計信息

  3 92 598 testfile # testfile文件的行數為3、單詞數92、字節數598

  其中,3 個數字分別表示testfile文件的行數、單詞數,以及該文件的字節數。

  如果想同時統計多個文件的信息,例如同時統計testfile、testfile_1、testfile_2,可使用如下命令:

  wc testfile testfile_1 testfile_2 #統計三個文件的信息

  輸出結果如下:

  $ wc testfile testfile_1 testfile_2 #統計三個文件的信息

  3 92 598 testfile #第一個文件行數為3、單詞數92、字節數598

  9 18 78 testfile_1 #第二個文件的行數為9、單詞數18、字節數78

  3 6 32 testfile_2 #第三個文件的行數為3、單詞數6、字節數32

  15 116 708 總用量 #三個文件總共的行數為15、單詞數116、字節數708

  linux系統中wc命令常見用法

  默認使用wc統計/etc/passwd

  #wc /etc/passwd

  40 45 1719 /etc/passwd

  40是行數,45是單詞數,1719是字節數

  wc的命令比較簡單使用,每個參數使用如下:

  #wc -l /etc/passwd #統計行數,在對記錄數時,很常用

  40 /etc/passwd #表示系統有40個賬戶

  #wc -w /etc/passwd #統計單詞出現次數

  45 /etc/passwd

  #wc -m /etc/passwd #統計文件的字節數

  1719

Copyright © Linux教程網 All Rights Reserved