Linux wcコマンド

Linux 命令大全Linuxコマンド大全

Linux wcコマンドは単語数を計算するために使用されます。

wcコマンドを使用すると、ファイルのバイト数、単語数、または行数を計算できます。ファイル名を指定しない場合、または指定されたファイル名が「-」の場合、wcコマンドは標準入力デバイスからデータを読み取ります。

構文

wc [-clw][--help][--version][文件...]

パラメータ:

  • -cまたは--bytesまたは--chars:バイト数のみを表示します。
  • -lまたは--lines:行数を表示します。
  • -wまたは--words:単語数のみを表示します。
  • --help:オンラインヘルプを表示します。
  • --version:バージョン情報を表示します。

使用例

デフォルトでは、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 命令大全Linuxコマンド大全

その他の拡張