wcコマンド~行数、単語数、文字数を表示する~【Linuxコマンド集】

ファイルの行数、単語数、文字数を表示します。オプションを省略すると、行数、単語数、文字数を表示します。
wcコマンドの基本
コマンドの基本動作
次の例は「0000.txt」ファイルの行数、単語数、文字数を表示しています。
wc [オプション] [ファイル名]

wcコマンドの主なオプション
オプション | 説明 |
---|---|
-c | 文字数(バイト数)を表示する |
-l | 行数を表示する |
-w | 単語数を表示する |
文字数を表示する
wc -c 0000.txt

行数を表示する
catコマンドでファイル内を表示させwcコマンド行数を表示させています。またwcコマンドから直接行数を表示させることも可能です。
cat 0000.txt | wc -l または wc -l 0000.txt

単語数を表示する
wc -w 0000.txt

-
前の記事
uniqコマンド~重複している行をまとめる~【Linuxコマンド集】 2021.08.09
-
次の記事
gzipコマンド~ファイルの圧縮、解凍~【Linuxコマンド集】 2021.08.13