Linux系统中的wc(Word Count)命令的功能为统计指定文件中的字节数、字数、行数,并将统计结果显示输出。

原文:http://blog.jobbole.com/109925/

http://blog.csdn.net/jerry_1126/article/details/52107947------图解

1.命令格式:

1
wc [选项]文件...

2.命令功能:

统计指定文件中的字节数、字数、行数,并将统计结果显示输出。该命令统计指定文件中的字节数、字数、行数。如果没有给出文件名,则从标准输入读取。wc同时也给出所指定文件的总统计数。

3.命令参数:

 
 
 
 
 

Shell

 
1
2
3
4
5
6
7
8
9
10
11
12
13
-c 统计字节数。
 
-l 统计行数。
 
-m 统计字符数。这个标志不能与 -c 标志一起使用。
 
-w 统计字数。一个字被定义为由空白、跳格或换行字符分隔的字符串。
 
-L 打印最长行的长度。
 
-help 显示帮助信息
 
--version 显示版本信息

4.使用实例:

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

命令:

 
 
 
 
 

Shell

 
1
wc test.txt

输出:

 
 
 
 
 

Shell

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
[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
 
7 test.txt
 
[root@localhost test]# wc -c test.txt
 
70 test.txt
 
[root@localhost test]# wc -w test.txt
 
8 test.txt
 
[root@localhost test]# wc -m test.txt
 
70 test.txt
 
[root@localhost test]# wc -L test.txt
 
17 test.txt

说明:

 
 
 
 
 

Shell

 
1
2
3
7     8     70     test.txt
 
行数 单词数 字节数 文件名

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

命令:

输出:

 
 
 
 
 

Shell

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

7 test.txt

 
 
 
 
 

Shell

 
1
2
3
[root@localhost test]# cat test.txt |wc -l
 
7[root@localhost test]#

说明:

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

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

命令:

 
 
 
 
 

Shell

 
1
ls -l | wc -l

输出:

 
 
 
 
 

Shell

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[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]#

说明:

数量中包含当前目录

最新文章

  1. asp.net将图片转成二进制存入数据库
  2. 更新整理本人所有博文中提供的代码与工具(C++,2013.11)
  3. hdu acm 2082 找单词
  4. Visual C++中的一些编程小技巧
  5. 红黑树(五)之 Java的实现
  6. Quartz.net misfire实践
  7. 一个短小的JS函数,用来得到仅仅包含不重复元素的数组
  8. VS2015使用技巧 打开代码片段C#部分
  9. Qt的Qss样式
  10. win8 64位操作系统 Microsoft Visual Studio 2010在IIS上调试 “此任务要求应用程序具有提升的权限”等问题
  11. ubuntu 12.04安装redis2.6.16
  12. 自动化制作.framework
  13. 使用yum安装不知道到底安装在什么文件夹
  14. EMMET 的HTM自动生成
  15. C++代码审查---审查孙晓宁马踏棋盘谜题程序
  16. day056-58 django多表增加和查询基于对象和基于双下划线的多表查询聚合 分组查询 自定义标签过滤器 外部调用django环境 事务和锁
  17. html 设置input框的记忆功能(联想内容)
  18. 计算机网络一:OSI七层、TCP/IP五层与TCP/IP四层
  19. linux 循环读取文件的每一行
  20. ie6-ie8支持CSS3选择器的解决办法

热门文章

  1. 如何得到DataTable的列名
  2. ubantu在登录界面一致循环的问题
  3. fiddler 的AutoRespoder的使用(手动添加测试桩)
  4. JVM插码之三:javaagent介绍及javassist介绍
  5. DNS Doctoring
  6. 浏览器重绘(repaint)和回流(reflow)的那点事
  7. Java探索之旅(10)——数组线性表ArrayList和字符串生成器StringBuffer/StringBuilder
  8. SharePoint 2013上传AI格式文件,再次下载后变成了PS格式文件
  9. EchoServer和EchoClient模型的改进1之多线程
  10. 关于login/interactive/no-interactive shell和profile/bash_profile/bashrc