linux基础命令之:Linux统计命令wc学习
2016-02-17 17:46
645 查看
Linux系统中的wc(Word Count)命令的功能为统计指定文件中的字节数、字数、行数,并将统计结果显示输出。
1、wc命令帮助
2、中文命令参数说明
统计指定文件中的字节数、字数、行数,并将统计结果显示输出。该命令统计指定文件中的字节数、字数、行数。如果没有给出文件名,则从标准输入读取。wc同时也给出所指定文件的总统计数。
-c 统计字节数。
-l 统计行数。
-m 统计字符数。这个标志不能与 -c 标志一起使用。
-w 统计字数。一个字被定义为由空白、跳格或换行字符分隔的字符串。
-L 打印最长行的长度。
-help 显示帮助信息
--version 显示版本信息
3、使用实例
实例1:查看文件的字节数、字数、行数
命令:
wc test.txt
实例2:用wc命令怎么做到只打印统计数字不打印文件名
命令:
输出:
[root@localhost test]# wc -l test.txt
7 test.txt
[root@localhost test]# cat test.txt |wc -l
7
说明:使用管道线,这在编写shell脚本时特别有用。
实例3:用来统计当前目录下的文件数
命令:
ls -l | wc -l
输出:
[root@localhost test6]# ls -l | wc -l
8
说明:数量中包含当前目录
实例4:
$ wc - lcw file1 file2
4 33 file1
7 52 file2
11 11 85 total
省略任选项-lcw,wc命令的执行结果与上面一样
实例5:
wc命令用来计算一个文件或者指定的多个文件中的行数,单词数和字符数。如:
wc filename
第一列显示行数,第二列显示单词数,第三列显示字符数。
wc 有四个参数可选,分别是l,c,m,w
wc -l filename 报告行数
wc -c filename 报告字节数
wc -m filename 报告字符数
wc -w filename 报告单词数
1、wc命令帮助
[spark@Master etl-script]$ 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. With no FILE, or when FILE is -, read standard input. -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 length of the longest line -w, --words print the word counts --help display this help and exit --version output version information and exit Report wc bugs to bug-coreutils@gnu.org GNU coreutils home page: <http://www.gnu.org/software/coreutils/> General help using GNU software: <http://www.gnu.org/gethelp/> For complete documentation, run: info coreutils 'wc invocation'
2、中文命令参数说明
统计指定文件中的字节数、字数、行数,并将统计结果显示输出。该命令统计指定文件中的字节数、字数、行数。如果没有给出文件名,则从标准输入读取。wc同时也给出所指定文件的总统计数。
-c 统计字节数。
-l 统计行数。
-m 统计字符数。这个标志不能与 -c 标志一起使用。
-w 统计字数。一个字被定义为由空白、跳格或换行字符分隔的字符串。
-L 打印最长行的长度。
-help 显示帮助信息
--version 显示版本信息
3、使用实例
实例1:查看文件的字节数、字数、行数
命令:
wc test.txt
实例2:用wc命令怎么做到只打印统计数字不打印文件名
命令:
输出:
[root@localhost test]# wc -l test.txt
7 test.txt
[root@localhost test]# cat test.txt |wc -l
7
说明:使用管道线,这在编写shell脚本时特别有用。
实例3:用来统计当前目录下的文件数
命令:
ls -l | wc -l
输出:
[root@localhost test6]# ls -l | wc -l
8
说明:数量中包含当前目录
实例4:
$ wc - lcw file1 file2
4 33 file1
7 52 file2
11 11 85 total
省略任选项-lcw,wc命令的执行结果与上面一样
实例5:
wc命令用来计算一个文件或者指定的多个文件中的行数,单词数和字符数。如:
wc filename
第一列显示行数,第二列显示单词数,第三列显示字符数。
wc 有四个参数可选,分别是l,c,m,w
wc -l filename 报告行数
wc -c filename 报告字节数
wc -m filename 报告字符数
wc -w filename 报告单词数
相关文章推荐
- 全面对战LILO 和 GRUB
- Linux虚拟化介绍
- Linux 引导过程内幕
- 深入理解Linux内核 Chapter1 introduction
- Linux top命令说明笔记
- Linux常用命令
- 每天一个linux命令---mount
- Linux内存管理之mmap详解
- centos(linux)普通用户设置sudo权限
- CentOS 7.1 上安装Cloudera Manager 管理的Hadoop
- linux date -d 的一些使用方法
- 拥抱开源,怎样关注Linux Kernel 邮件列表?
- Linux学习笔记--ln命令(链接命令)
- Linux设备驱动之中断与定时器
- centos6.4编译hadoop2.4源码
- 在Centos系统中搭建Hadoop集群
- 在Linux系统中如何查看和关闭SELinux
- Linux 初始 RAM 磁盘(initrd)概述
- 【Linux运维入门】Nexus索引更新和仓库迁移
- linux 下的一些profile工具 c++