Linux命令篇 - wc 命令

wc

wc - print newline, word, and byte counts for each file

wc: 统计文件的字节数字数行数

格式: wc [OPTION]... [FILE]...

常用参数:

OPTION 意义
-w 统计字数,或--words:只显示字数。一个字被定义为由空白、跳格或换行字符分隔的字符串
-c 统计字节数,或--bytes或--chars:只显示Bytes数
-l 统计行数,或--lines:只显示列数
-m 统计字符数
-L 打印最长行的长度
--help 显示帮助信息
--version 显示版本信息

参考示例:

  • 统计字数
# 创建 test.out 文件
$ vi test.out
hello world
hello world
hello world
hello world hello world

# 查看 test.out 文件
$ cat test.out 
hello world
hello world
hello world
hello world hello world
$ wc -w test.out
10 test.txt
  • 统计字节数
$ wc -c test.out 
60 test.txt
  • 统计字符数
$ wc -m test.out 
60 test.txt
  • 统计单词数
$ wc -w test.out
10 test.out
  • 统计行数单词数字节数
$ wc test.out   //等价于 wc -lwc test.out
4 10 60 test.out
  • 统计行数
$ wc -l test.out 
4 test.out
  • 打印最长行的长度
$ wc -L test.out 
23 test.out
posted @ 2022-09-28 11:16  HOsystem  阅读(134)  评论(0编辑  收藏  举报