Linux的 wc 命令详解

#
wc –help

用法:wc [选项]... [文件]...
 或:wc [选项]... --files0-from=F
输出每个指定文件的行数、单词计数和字节数,如果指定了
多于一个文件,继续给出所有相关数据的总计。如果没有指定
文件,或者文件为"-",则从标准输入读取数据。
  -c, --bytes           输出字节数统计
  -m, --chars           输出字符数统计
  -l, --lines           输出行数统计
      --files0-from=文件        从指定文件读取以NUL 终止的名称,如果该文件被
                                        指定为"-"则从标准输入读文件名
  -L, --max-line-length 显示最长行的长度
  -w, --words                   显示单词计数
      --help            显示此帮助信息并退出
      --version         显示版本信息并退出

请向bug-coreutils@gnu.org 报告wc 的错误
GNU coreutils 项目主页:<http://www.gnu.org/software/coreutils/>
GNU 软件一般性帮助:<http://www.gnu.org/gethelp/>
请向<http://translationproject.org/team/zh_CN.html> 报告wc 的翻译错误
要获取完整文档,请运行:info coreutils 'wc invocation'


使用实例


实例1:查看文件的字节数、字数、行数

[root@localhost test]# cat test.txt 

hnlinux

peida.cnblogs.com

ubuntu

ubuntu linux

redhat

Redhat

linuxmint

[root@localhost test]# wc test.txt

 7  8 70 test.txt

[root@localhost test]# wc -l test.txt 

test.txt

[root@localhost test]# wc -c test.txt 

70 test.txt

[root@localhost test]# wc -w test.txt 

test.txt

[root@localhost test]# wc -m test.txt 

70 test.txt

[root@localhost test]# wc -L test.txt 

17 test.txt

说明:

7     8     70     test.txt

行数 单词数 字节数 文件名


实例2:用wc命令怎么做到只打印统计数字不打印文件名

[root@localhost test]# wc -l test.txt 

test.txt

[root@localhost test]# cat test.txt |wc -l

7[root@localhost test]#

说明:使用管道线,这在编写shell脚本时特别有用。


实例3:用来统计当前目录下的文件数

[root@localhost test]# cd test6

[root@localhost test6]# ll

总计 604

—xr–r– 1 root mail  302108 11-30 08:39 linklog.log

—xr–r– 1 mail users 302108 11-30 08:39 log2012.log

-rw-r–r– 1 mail users     61 11-30 08:39 log2013.log

-rw-r–r– 1 root mail       0 11-30 08:39 log2014.log

-rw-r–r– 1 root mail       0 11-30 08:39 log2015.log

-rw-r–r– 1 root mail       0 11-30 08:39 log2016.log

-rw-r–r– 1 root mail       0 11-30 08:39 log2017.log

[root@localhost test6]# ls -l | wc -l

8

[root@localhost test6]#

说明:数量中包含当前目录

实例部分,转自:http://www.cnblogs.com/peida/archive/2012/12/18/2822758.html

标签