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 @   HOsystem  阅读(165)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
点击右上角即可分享
微信分享提示