linux shell命令wc使用详解

为什么由这个小短文
在kernel 顶层Makefile中有如下代码,这部分代码是用于生成UTS_RELEASE的。其中UTS长度通过wc -c命令来检查。

1168 uts_len := 64
1169 define filechk_utsrelease.h
1170         if [ `echo -n "$(KERNELRELEASE)" | wc -c ` -gt $(uts_len) ]; then \
1171           echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2;    \
1172           exit 1;                                                         \
1173         fi;                                                               \
1174         echo \#define UTS_RELEASE \"$(KERNELRELEASE)\"
1175 endef

1. wc命令含义

qemu@qemu:~/linux-5.4.124$ wc --help
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.  A word is a non-zero-length sequence of
characters delimited by white space.

With no FILE, or when FILE is -, read standard input.

The options below may be used to select which counts are printed, always in
the following order: newline, word, character, byte, maximum line length.
  -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 maximum display width
  -w, --words            print the word counts
      --help     display this help and exit
      --version  output version information and exit

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Full documentation at: <http://www.gnu.org/software/coreutils/wc>
or available locally via: info '(coreutils) wc invocation'
qemu@qemu:~/linux-5.4.124$

2. wc使用

  • 统计文件包含的字符个数
    注意,统计字符个数是包含空格的。
qemu@qemu:~$ cat wc.txt | wc -c
12

qemu@qemu:~$ ll wc.txt
-rw-rw-r-- 1 qemu qemu 12 917 18:55 wc.txt
qemu@qemu:~$
  • 统计文件word数
    统计word个数的时候是以空格为划分的
qemu@qemu:~$ cat wc.txt | wc -w
4
qemu@qemu:~$ cat wc.txt
aa bb cc dd
  • 统计文件行数
qemu@qemu:~$ cat wc.txt |wc -l
1
qemu@qemu:~$

qemu@qemu:~$ cat wc.txt
aa bb cc dd
qemu@qemu:~$
  • 统计最大显示宽度
qemu@qemu:~$ cat wc.txt |wc -L
11
qemu@qemu:~$

qemu@qemu:~$ cat wc.txt
aa bb cc dd
qemu@qemu:~$
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Linux与SoC

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值