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
分类:
Bash Shell
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统