Linux ~ 查看日志的常用命令总结

1.tail

-n <行数>,显示文件的尾部n行内容。

-f 循环读取,常用于查阅正在改变的日志文件。

① tail -f test.log 实时显示test.log文件里的最尾部的内容,只要test.log更新就可以看到最新的文件内容。

② tail -100f test.log 实时监控100行日志。

③ tail -n 100 test.log 查询日志尾部最后100行日志内容。

复制代码
  ④ tail  -n  +100  test.log   查询100行之后所有的日志内容。

2.head

①head -n 100 test.log 查询日志文件中的头100行日志。

②head -n -100 test.log 查询日志文件中除了最后100行的其他内容。

3.grep

①grep "debug" test.log 查询test.log中所有含有debug关键字的记录

4.more和less

①cat -n test.log | grep "debug" test.log | more 这样就可以分页打印了,通过点击空格键翻页。

5.使用>xxxx.txt将查到的日志保存到文件中。

①cat -n test.log |grep "debug" >debug.txt

相关推荐
瀚高PG实验室3 分钟前
rpm包安装报错:cannot open Packages index using db5 - Cannot allocate memory (12)
linux·运维·服务器·瀚高数据库
追风少年王大爷丶11 分钟前
nginx 配置无域名访问拒绝
运维·服务器·nginx
AI+程序员在路上14 分钟前
嵌入式软件技术大全
linux·开发语言·arm开发·单片机
black方块cxy20 分钟前
实现一个输入框多个ip以逗号分隔最多20组,且ip不能重复
java·服务器·前端
Snasph33 分钟前
在Ubuntu上进行端口转发
linux·运维·ubuntu
线束线缆组件品替网35 分钟前
Amphenol RJE1Y22A53644401线束详解与替代网络线束选型指南
运维·服务器·网络·智能路由器·电脑·51单片机
TG_yunshuguoji1 小时前
阿里云代理商: 阿里云部署OpenClaw 个性化配置指南 3 大场景模板详解
服务器·阿里云·云计算·openclaw
23.1 小时前
【Java】char字符类型的UTF-16编码解析
java·开发语言·面试
怒放吧德德1 小时前
Spring Boot实战:InfluxDB 2.x简单教程
java·spring boot·后端
indexsunny1 小时前
互联网大厂Java面试实战:核心技术与业务场景深度解析
java·spring boot·hibernate·security·microservices·interview