Linux 统计命令之 wc 命令详解

文章
林里克斯

wc(word count) 命令用于统计一个文件中的行数、字数、字节数或字符数。

Linux 统计命令之 wc 命令详解


实验平台:CentOS 7.7.1908

wc (GNU coreutils) version:8.22



一、 wc 命令详解


$ wc --help
Usage: wc [OPTION]... [FILE]...

  -c, --bytes            #统计字节数(与 -m 输出一致)
  -m, --chars            #统计字符数
  -l, --lines            #统计行数(空行也统计)
  -L, --max-line-length  #打印最长行的长度
  -w, --words            #打印单词数
  --help                #打印帮助信息
  --version           #打印版本信息

二、 使用案例


$ cat centos.txt 
The CentOS Project is a community-driven free software effort focused on delivering a robust open source ecosystem around a Linux platform.
Community-driven free software effort focused on delivering a robust open source ecosystem around a Linux platform.
The CentOS Linux distribution is a stable, predictable, manageable and reproducible platform derived from the sources of Red Hat Enterprise Linux (RHEL). We are now looking to expand on that by creating the resources needed by other communities to come together and be able to build on the CentOS Linux platform. And today we start the process by delivering a clear governance model, increased transparency and access. In the coming weeks we aim to publish our own roadmap that includes variants of the core CentOS Linux.

Since March 2004, CentOS Linux has been a community-supported distribution derived from sources freely provided to the public by Red Hat. As such, CentOS Linux aims to be functionally compatible with RHEL. We mainly change packages to remove upstream vendor branding and artwork. CentOS Linux is no-cost and free to redistribute.

CentOS Linux is developed by a small but growing team of core developers. In turn the core developers are supported by an active user community including system administrators, network administrators, managers, core Linux contributors, and Linux enthusiasts from around the world.

Over the coming year, the CentOS Project will expand its mission to establish CentOS Linux as a leading community platform for emerging open source technologies coming from other projects such as OpenStack. These technologies will be at the center of multiple variations of CentOS, as individual downloads or accessed from a custom installer. Read more about the variants and Special Interest Groups that produce them.

1.wc 默认统计文件的行数、字数,以及字节数。(可以统计多个文件,会依次列出所跟文件的统计信息)

$ wc centos.txt 
   9  280 1811 centos.txt
#相当于 -lwc
$ wc -lwc centos.txt
   9  280 1811 centos.txt

2.统计行数

$ wc -l centos.txt 
9 centos.txt
#如果只需要输出行数不输出文件名字,可以这样操作
$ cat centos.txt | wc -l
9

3.统计字节数

$ cat test.txt 
1
2
3
 4
$ wc -c test.txt 
9 test.txt
#为什么有 9 个,这是因为包括了空格符以及每行的换行符
$ cat -A test.txt
#查看换行符
1$
2$
3$
 4$

Over~

版权协议须知!

本篇文章来源于 Uambiguous ,如本文章侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意

692 0 2020-11-06


分享:
icon_mrgreen.gificon_neutral.gificon_twisted.gificon_arrow.gificon_eek.gificon_smile.gificon_confused.gificon_cool.gificon_evil.gificon_biggrin.gificon_idea.gificon_redface.gificon_razz.gificon_rolleyes.gificon_wink.gificon_cry.gificon_surprised.gificon_lol.gificon_mad.gificon_sad.gificon_exclaim.gificon_question.gif
博主卡片
林里克斯 博主大人
一个致力于Linux的运维平台
运维时间
搭建这个平台,只为分享及记载自己所遇之事和难题。

现在时间 2024-04-29

今日天气
站点统计
  • 文章总数:240篇
  • 分类总数:29个
  • 评论总数:10条
  • 本站总访问量 216864 次

@奥奥

@Wong arrhenius 牛比

@MakerFace 厉害了!