欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

命令三十二: wc

程序员文章站 2024-02-24 11:11:52
...

wc命令(Word Count)用来统计指定文件中的行数,字数,字节数,并显示统计结果。命令格式为cat [选项] 文件,如果没有显示地给出文件名,则从标准输入获取数据。

1. 查看文件的行数,字数和字节数

[email protected]:~# cat test.txt
aaa
word
bbb ccc
ddddd
ecsa
[email protected]:~# wc test.txt
 5  6 28 test.txt

2. 单独统计

# 不加参数
[email protected]:~# wc test.txt
 5  6 28 test.txt
# 统计字节数
[email protected]:~# wc -c test.txt
28 test.txt
# 统计行数
[email protected]:~# wc -l test.txt
5 test.txt
# 统计字符数
[email protected]:~# wc -m test.txt
28 test.txt
# 统计字数
[email protected]:~# wc -w test.txt
6 test.txt

3. 利用管道符从标准输入获取输入文件

[email protected]:~# cat test.txt | wc -l
5

4. 统计当前目录中的文件个数

[email protected]:~# ls -l | wc -l
8

参考:https://www.cnblogs.com/peida/archive/2012/12/18/2822758.html

相关标签: linux wc