Linux的 wc 命令详解

Linux的 wc 命令详解wchelp 用法 wc 选项 文件 或 wc 选项 files0 from F 输出每个指定文件的行数 单词计数和字节数 如果指定了 多于一个文件 继续给出所有相关数据的总

大家好,欢迎来到IT知识分享网。

wc –help

  1. 用法:wc [选项]... [文件]...
  2.  或:wc [选项]... --files0-from=F
  3. 输出每个指定文件的行数、单词计数和字节数,如果指定了
  4. 多于一个文件,继续给出所有相关数据的总计。如果没有指定
  5. 文件,或者文件为"-",则从标准输入读取数据。
  6. -c, --bytes 输出字节数统计
  7. -m, --chars 输出字符数统计
  8. -l, --lines 输出行数统计
  9. --files0-from=文件 从指定文件读取以NUL 终止的名称,如果该文件被
  10. 指定为"-"则从标准输入读文件名
  11. -L, --max-line-length 显示最长行的长度
  12. -w, --words 显示单词计数
  13. --help 显示此帮助信息并退出
  14. --version 显示版本信息并退出
  15.  
  16. 请向 报告wc 的错误
  17. GNU coreutils 项目主页:<http://www.gnu.org/software/coreutils/>
  18. GNU 软件一般性帮助:<http://www.gnu.org/gethelp/>
  19. 请向<http://translationproject.org/team/zh_CN.html> 报告wc 的翻译错误
  20. 要获取完整文档,请运行: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 

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

 

说明:

7     8     70     test.txt

行数 单词数 字节数 文件名

 

 

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

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

7 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   11-30 08:39 linklog.log

—xr–r– 1 mail users  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]#

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

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/155516.html

(0)
上一篇 2025-02-18 19:26
下一篇 2025-02-18 19:33

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注微信