当前位置: 首页 > news >正文

Linux查看文件的行数,字数,字节数

介绍

在Linux系统中这统计非常方便,只需要简单的几个命令就可以搞定,这个命令就是 wc

wc --help
用法:wc [选项]... [文件]...或:wc [选项]... --files0-from=F
输出每个指定文件的行数、单词计数和字节数,如果指定了
多于一个文件,继续给出所有相关数据的总计。如果没有指定
文件,或者文件为"-",则从标准输入读取数据。-c, --bytes        输出字节数统计-m, --chars        输出字符数统计-l, --lines        输出行数统计--files0-from=文件    从指定文件读取以NUL 终止的名称,如果该文件被指定为"-"则从标准输入读文件名-L, --max-line-length    显示最长行的长度-w, --words            显示单词计数--help        显示此帮助信息并退出--version        显示版本信息并退出

使用实例

  • 获取文件行数
wc -l app.log
30000 app.log
  • 获取文件单词数
wc -w app.log
30000 app.log
  • 获取文件字节数
wc -c app.log
3000 app.log

grep

查询文件的行数或字数只是个简单的需求场景,有时候我们其实是要获取多少匹配关键字的行数,那么这种情况如何实现呢,这种情况我们需要使用另外一个grep命令来配置wc来完成我们的需求场景。

lennlouis@dpdk-vm:~$ grep --help
Usage: grep [OPTION]... PATTERNS [FILE]...
Search for PATTERNS in each FILE.
Example: grep -i 'hello world' menu.h main.c
PATTERNS can contain multiple patterns separated by newlines.Pattern selection and interpretation:-E, --extended-regexp     PATTERNS are extended regular expressions-F, --fixed-strings       PATTERNS are strings-G, --basic-regexp        PATTERNS are basic regular expressions-P, --perl-regexp         PATTERNS are Perl regular expressions-e, --regexp=PATTERNS     use PATTERNS for matching-f, --file=FILE           take PATTERNS from FILE-i, --ignore-case         ignore case distinctions in patterns and data--no-ignore-case      do not ignore case distinctions (default)-w, --word-regexp         match only whole words-x, --line-regexp         match only whole lines-z, --null-data           a data line ends in 0 byte, not newlineMiscellaneous:-s, --no-messages         suppress error messages-v, --invert-match        select non-matching lines-V, --version             display version information and exit--help                display this help text and exitOutput control:-m, --max-count=NUM       stop after NUM selected lines-b, --byte-offset         print the byte offset with output lines-n, --line-number         print line number with output lines--line-buffered       flush output on every line-H, --with-filename       print file name with output lines-h, --no-filename         suppress the file name prefix on output--label=LABEL         use LABEL as the standard input file name prefix-o, --only-matching       show only nonempty parts of lines that match-q, --quiet, --silent     suppress all normal output--binary-files=TYPE   assume that binary files are TYPE;TYPE is 'binary', 'text', or 'without-match'-a, --text                equivalent to --binary-files=text-I                        equivalent to --binary-files=without-match-d, --directories=ACTION  how to handle directories;ACTION is 'read', 'recurse', or 'skip'-D, --devices=ACTION      how to handle devices, FIFOs and sockets;ACTION is 'read' or 'skip'-r, --recursive           like --directories=recurse-R, --dereference-recursive  likewise, but follow all symlinks--include=GLOB        search only files that match GLOB (a file pattern)--exclude=GLOB        skip files that match GLOB--exclude-from=FILE   skip files that match any file pattern from FILE--exclude-dir=GLOB    skip directories that match GLOB-L, --files-without-match  print only names of FILEs with no selected lines-l, --files-with-matches  print only names of FILEs with selected lines-c, --count               print only a count of selected lines per FILE-T, --initial-tab         make tabs line up (if needed)-Z, --null                print 0 byte after FILE nameContext control:-B, --before-context=NUM  print NUM lines of leading context-A, --after-context=NUM   print NUM lines of trailing context-C, --context=NUM         print NUM lines of output context-NUM                      same as --context=NUM--color[=WHEN],--colour[=WHEN]       use markers to highlight the matching strings;WHEN is 'always', 'never', or 'auto'-U, --binary              do not strip CR characters at EOL (MSDOS/Windows)When FILE is '-', read standard input.  With no FILE, read '.' if
recursive, '-' otherwise.  With fewer than two FILEs, assume -h.
Exit status is 0 if any line (or file if -L) is selected, 1 otherwise;
if any error occurs and -q is not given, the exit status is 2.Report bugs to: bug-grep@gnu.org
GNU grep home page: <http://www.gnu.org/software/grep/>
General help using GNU software: <https://www.gnu.org/gethelp/>
  • 查询文件中单词的行数
grep 'hello' app.log | wc -l

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 207 课程表
  • 如何在PD虚拟机中开启系统的嵌套虚拟化功能?pd虚拟机怎么用 Parallels Desktop 19 for Mac
  • Pytorch(笔记7损失函数类型)
  • 1-5题查询 - 高频 SQL 50 题基础版
  • Floyd
  • 如何给gitlab其他访问者创建账号并增加权限
  • Java+Vue实现电商网站
  • Http中get与post的区别,99%的人都理解错了吧
  • 算法题-回文子串和最长回文子序列
  • 使用Python实现深度学习模型:模型解释与可解释人工智能
  • 最长公共子序列求长度和输出子序列C代码
  • 大数的排列组合公式C代码
  • 08_排序
  • 云原生之容器编排实践-OpenEuler23.09在线安装Kubernetes与KubeSphere
  • uni-app怎样使用组件
  • 【mysql】环境安装、服务启动、密码设置
  • Angular4 模板式表单用法以及验证
  •  D - 粉碎叛乱F - 其他起义
  • HashMap剖析之内部结构
  • httpie使用详解
  • Magento 1.x 中文订单打印乱码
  • node入门
  • php面试题 汇集2
  • 大整数乘法-表格法
  • 复习Javascript专题(四):js中的深浅拷贝
  • 高程读书笔记 第六章 面向对象程序设计
  • 高性能JavaScript阅读简记(三)
  • 海量大数据大屏分析展示一步到位:DataWorks数据服务+MaxCompute Lightning对接DataV最佳实践...
  • 来,膜拜下android roadmap,强大的执行力
  • 前端js -- this指向总结。
  • 如何邀请好友注册您的网站(模拟百度网盘)
  • 使用putty远程连接linux
  • 数据科学 第 3 章 11 字符串处理
  • 微信小程序上拉加载:onReachBottom详解+设置触发距离
  • 字符串匹配基础上
  • ​​​【收录 Hello 算法】10.4 哈希优化策略
  • ​​快速排序(四)——挖坑法,前后指针法与非递归
  • # 再次尝试 连接失败_无线WiFi无法连接到网络怎么办【解决方法】
  • #565. 查找之大编号
  • #我与Java虚拟机的故事#连载04:一本让自己没面子的书
  • #我与Java虚拟机的故事#连载11: JVM学习之路
  • $.type 怎么精确判断对象类型的 --(源码学习2)
  • (06)Hive——正则表达式
  • (6) 深入探索Python-Pandas库的核心数据结构:DataFrame全面解析
  • (delphi11最新学习资料) Object Pascal 学习笔记---第7章第3节(封装和窗体)
  • (八)Flask之app.route装饰器函数的参数
  • (笔试题)分解质因式
  • (多级缓存)多级缓存
  • (附源码)springboot 智能停车场系统 毕业设计065415
  • (附源码)计算机毕业设计ssm-Java网名推荐系统
  • (计算机网络)物理层
  • (十)c52学习之旅-定时器实验
  • (十七)Flask之大型项目目录结构示例【二扣蓝图】
  • (十一)图像的罗伯特梯度锐化
  • (原創) 人會胖會瘦,都是自我要求的結果 (日記)