Linux基础命令[9]-wc

1. wc 命令说明

wc(word count):可以计算文件的Byte数、字符数、或是列数,基本信息如下:

Usage: wc [OPTION]... [FILE]...
  or:  wc [OPTION]... --files0-from=F
Print newline, word, and byte counts for each FILE, and a total line if
more than one FILE is specified.  With no FILE, or when FILE is -,
read standard input.
  -c, --bytes            print the byte counts
  -m, --chars            print the character counts
  -l, --lines            print the newline counts
      --files0-from=F    read input from the files specified by
                           NUL-terminated names in file F;
                           If F is - then read names from standard input
  -L, --max-line-length  print the length of the longest line
  -w, --words            print the word counts
      --help     display this help and exit
      --version  output version information and exit

Report wc bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'wc invocation'

参数如下:

选项作用
-c统计字节数
-m统计字符数
-l统计行数
-L统计最长行的长度
-w统计单词数

2. wc 命令语法

wc [选项] 文件名

3. wc 命令示例

3.1 不加参数

此时,会展示出文件的行数、单词数、字节数

wc 文件名

在这里插入图片描述

3.2 -c(统计字节数)

-c:统计字节数,空格、换行符也算

wc -c 文件名

在这里插入图片描述

3.3 -m(统计字符数)

-m:统计字符数,空格、换行符也算

wc -m 文件名

在这里插入图片描述

3.4 -l(统计行数)

-l:统计行数,没啥说的,有几行就是几行

wc -l 文件名

在这里插入图片描述

3.5 -L(最长一行的长度)

-L:统计最长一行的长度,不算换行符。但是有个疑问,英文1个字母是一个长度,1个中文却是2个长度,但是我系统的字符集是 utf-8 ,查了一些资料也没找到原因,有知道的大神告诉我一下,感谢。

wc -L 文件名

在这里插入图片描述

3.6 -w(统计单词数)

-w:统计单词数,由空格或者换行符隔开才算一个单词

wc -w 文件名

在这里插入图片描述

4. 总结

wc 统计文件字节、字符、行数等信息。某些时候,脚本里面会用的

wc -l

去统计结果。

  • 7
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值