Linux(Centos 7.6)命令详解:wc

打印 上一主题 下一主题

主题 1768|帖子 1768|积分 5304

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
1.命令作用

打印文件的行数、单词数、字节数,如果指定了多个文件,还会打印以上三种数据的总和(Print newline, word, and byte counts for each FILE, and a total line if more than one FILE is specified)
2.命令语法

Usage:  wc [OPTION]... [FILE]...
       or:  wc [OPTION]... --files0-from=F

3.参数详解

OPTION:


  • -c, --bytes,打印字节数
  • -m, --chars,打印字符数
  • -l, --lines,打印行数
  • --files0-from=F/-,F代表一个文件名,文件名内容为多个文件的名称,用于获取多个文件的行数、单词数、字节数,多个文件以一个零字节(ASCII NUL)结束;当利用 - 时,以其他输出为输入,如find利用-print0参数
  • -L, --max-line-length,打印最长行的长度
  • -w, --words,打印单词数
4.常用用例

4.1.常见的用例

  1. ## 不加参数,会依次打印行数、单词数、字节数
  2. [root@node2 Desktop]# wc test.txt
  3.   5  44 245 test.txt
  4. ## 多个文件时,最后会打印total总计数据
  5. [root@node2 Desktop]# wc test.txt test1.txt
  6.   5  44 245 test.txt
  7.   8   9  57 test1.txt
  8. 13  53 302 total
  9. ## 常用参数-l 用于查看文件行数
  10. [root@node2 Desktop]# wc -l test.txt
  11. 5 test.txt
  12. ## 常用参数-L 用于查看文件中最长的行的长度
  13. [root@node2 Desktop]# wc -L test.txt
  14. 72 test.txt
复制代码
 4.2.有效但不常见的用例

  1. ## --files0-from=F 参数使用
  2. ## vi打开文件如下,"^@"是一个字符,vi中输入方法为Ctrl+v,然后接着 Ctrl+@
  3. [root@node2 Desktop]# vi file
  4. test1.txt^@test2.txt^@test3.txt^@
  5. ~                                                                                                              
  6. ~                                                                                                              
  7. ~                                                                                                              
  8. ~                                                                                                              
  9. ~                                                                                                              
  10. ~                                                                                                              
  11. ~                                                                                                              
  12. ~                                                                                                                                                                                                                        
  13. "file" [noeol] 1L, 30C
  14. [root@node2 Desktop]# cat file               ## cat查看如下
  15. test1.txttest2.txttest3.txt
  16. [root@node2 Desktop]#
  17. [root@node2 Desktop]# truncate -s -1 file    ## 删除文件最后一个字符(换行符)
  18. [root@node2 Desktop]#
  19. [root@node2 Desktop]# cat file               ## 再次查看与上面对比
  20. test1.txttest2.txttest3.txt[root@node2 Desktop]#
  21. [root@node2 Desktop]#
  22. [root@node2 Desktop]# wc --files0-from=file  ## 可正常指定文件列表进行统计
  23.   8   9  57 test1.txt
  24.   9   9  63 test2.txt
  25.   4   4  28 test3.txt
  26. 21  22 148 total
  27. [root@node2 Desktop]#
  28. #########################################################################
  29. #########################################################################
  30. ## --files0-from=- 参数使用
  31. ## find中-print0参数的作用是在输出文件名时使用null字符(\0)作为分隔符,而不是换行符
  32. [root@node2 Desktop]# find . -name '*.txt' -print0 | wc -l --files0-from=-
  33. 4 ./test3.txt
  34. 9 ./test2.txt
  35. 8 ./test1.txt
  36. 5 ./test.txt
  37. 26 total
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

天津储鑫盛钢材现货供应商

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表