wc命令帮助

$ 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'

命令使用

统计行数

$ wc -l /usr/share/dict/american-english
/usr/share/dict/american-english

统计词数

$ wc -w /usr/share/dict/american-english
/usr/share/dict/american-english

统计字符数

wc -m /usr/share/dict/american-english
/usr/share/dict/american-english

统计字节数

wc -c /usr/share/dict/american-english
/usr/share/dict/american-english

注意-c和-m的区别在于对于多字节字符, 例如GBK, UTF-8编码的中文, 在-m中记一个, 在-c中记多个, 例如下面的测试, ubuntu默认编码是UTF-8, 中文是3个字节

$ echo -n "123,  测试"|wc -c

$ echo -n "123,  测试"|wc -m

统计最长的行

$ wc -L /usr/share/dict/american-english
/usr/share/dict/american-english

如果只希望获取数字, 不打印文件名, 可以通过以下两种方法, 从节约内存的角度看, 推荐前一种方法

$ wc -l /usr/share/dict/american-english | awk '{print $1}'

$ cat /usr/share/dict/american-english | wc -l

Linux下wc命令统计文件行数/词数/字符数/最长行字符数的更多相关文章

  1. linux 使用wc命令统计文件行数、字数及大小

    语法:wc [选项] 文件… 说明:该命令统计给定文件中的字节数.字数.行数.如果没有给出文件名,则从标准输入读取.wc同时也给出所有指定文件的总统计数.字是由空格字符区分开的最大字符串. 该命令各选 ...

  2. 【Linux】常用命令-统计代码行数

    公司人员流动大,经常有新的维护任务,交接时喜欢看看新来的模块的代码量,那么问题来了, 如何统计代码行数? 1,最先想到的肯定是 wc. wc -l *.h 将查看[当前目录]下头文件的代码行数,输出结 ...

  3. linux下sed命令对文件执行文本替换

    让我们看一下 sed 最有用的命令之一,替换命令.使用该命令,可以将特定字符串或匹配的规则表达式用另一个字符串替换.下面是该命令最基本用法的示例: $ sed -e ‘s/foo/bar/’ myfi ...

  4. linux下vi命令修改文件及保存的使用方法

    进入vi的命令 vi filename :打开或新建文件,并将光标置于第一行首 vi n filename :打开文件,并将光标置于第n行首 vi filename :打开文件,并将光标置于一行首 v ...

  5. (转)linux下vi命令修改文件及保存的使用方法

    进入vi的命令         vi filename :打开或新建文件,并将光标置于第一行首    vi n filename :打开文件,并将光标置于第n行首    vi filename :打开 ...

  6. Linux wc -l 统计文件行数存在的问题

    1.使用这种方式效率较低,而且不注意可能出现错误 find  . -name "*.pc" |xargs wc -l 直接查看 total 不是正确的值. 原因: 这种方式存在一个 ...

  7. Linux下wc命令详解

    功能说明:计算字数. 语   法:wc [-clw][--help][--version][文件…] 补充说明:利用wc指令我们可以计算文件的Byte数.字数.或是列数,若不指定任何文件名称,或是所给 ...

  8. win7和linux下利用命令查看文件md5、sha1、sha256

    win7 certutil -hashfile <filename> MD5 certutil -hashfile <filename> SHA1 certutil -hash ...

  9. Linux下Sed命令替换文件中的所有IP

    命令: sed -ri 's/([0-9]{1,3}\.){3}[0-9]{1,3}/localhost/g' es_create_index.sh 如图:

随机推荐

  1. 【ContestHunter】【弱省胡策】【Round7】

    Prufer序列+高精度+组合数学/DP+可持久化线段树 Magic 利用Prufer序列,我们考虑序列中每个点是第几个插进去的,再考虑环的连接方式,我们有$$ans=\sum_{K=3}^n N^{ ...

  2. Go语言之进阶篇操作redis

    1.windows安装redis 软件包下载地址: https://github.com/MicrosoftArchive/redis/releases 1.1.安装--->下一步---> ...

  3. easyui基于web的打印实现 .

    <%@ page language="java"pageEncoding="UTF-8"%> <object id="WebBrow ...

  4. random_state 参数

    SVC(random_state=0)里有参数 random_state random_state 相当于随机数种子,下面会有代码来解释其作用.图中设置了 random.seed() 就相当于在 SV ...

  5. Android -- queryIntentActivities

    某些时候你想要知道某个APP是否有注册了一个明确的intent,比如说你想要检查某个receiver是否存在,然后根据是否存在来这个receiver来在你的AP里面enable某些功能.我们可以通过P ...

  6. Android -- startActivityForResult和setResult

    startActivityForResult与startActivity的不同之处 startActivity( ) 仅仅是跳转到目标页面,若是想跳回当前页面,则必须再使用一次startActivit ...

  7. [Canvas]碰撞球 增加小球间碰撞检测

    请点此下载代码并用Chrome或是Firefox打开index.html 图例: 代码: <!DOCTYPE html> <html lang="utf-8"&g ...

  8. Wifidog协议V1

    Wifidog网关协议V1 网关心跳(Ping协议) Wifidog将ping协议作为心跳机制向认证服务器发送当前状态信息.这可以实现为认证服务器每个节点的状态生成中央日志. Wifidog客户端在c ...

  9. WIN10 64位系统 如何安装.NET Framwork3.5

    把SXS文件夹复制到C盘根目录,然后以管理员身份运行CMD,大概2分钟能完成,然后这个SXS文件夹就可以删了        

  10. 使用Feign时报错Service id not legal hostname

    报错Service id not legal hostname的原因是服务名称不能带有下划线,可以使用中划线