1、概述
打印文件的行数、单词数、字节数。该命令统计指定文件中的字节数、字数、行数。如果没有给出文件名,则从标准输入读取。wc同时也给出所指定文件的总统计数。
2、命令格式
wc [OPTION]… [FILE]…
wc [OPTION]… –files0-from=F
3、常用命令参数
-c, –bytes 打印字节数
-m, –chars 打印字符数【与 -c 相比英文没有区别,但是中文有区别】
-l, –lines 打印行数
-w, –words 打印单词数
-L, –max-line-length 打印最长行的长度
4、常用示例
1、查看文件的字节数、字数、行数
-bash-4.1$ wc application.properties 43 59 1651 application.properties -bash-4.1$ wc -c application.properties 1651 application.properties -bash-4.1$ wc -m application.properties 1651 application.properties -bash-4.1$ wc -w application.properties 59 application.properties -bash-4.1$ wc -l application.properties 43 application.properties -bash-4.1$ wc -L application.properties 144 application.properties
2、用wc命令怎么做到只打印统计行数不打印文件名
-bash-4.1$ wc -l application.properties 43 application.properties -bash-4.1$ cat application.properties | wc -l 43
3、统计当前文件数量
-bash-4.1$ ls -l total 665208 drwxrwxrwx 9 wit wit 4096 Jan 27 10:13 oss_tomcat_test -rw-r--r-- 1 wit wit 680488960 Jun 11 14:21 oss_tomcat_test.tar drwxrwxr-x 3 wit wit 4096 Jul 20 11:16 woshop drwxrwxr-x 2 wit wit 4096 Jul 15 21:03 woshop_test -bash-4.1$ ls -l | wc -l 5
5、命令所在位置和类型
-bash-4.1$ which wc /usr/bin/wc -bash-4.1$ type wc wc is hashed (/usr/bin/wc)
原文始发于:Linux wc 命令