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

相关推荐
周GZ几秒前
简单讲解Java中静态方法与 实例方法
java·开发语言
疯狂打码的少年11 分钟前
【数据结构】树的基本概念与二叉树定义
java·数据结构·笔记·算法
气泡水。15 分钟前
RHCSA笔记实记
linux·笔记
波特率11520016 分钟前
linux当中的六大进程间通信方式
linux·嵌入式·ipc
RisunJan28 分钟前
Linux命令-ssh-keyscan(从主机收集公钥)
linux·ssh
こ进制掌控者39 分钟前
局域网电脑SMB访问NAS,提示用户名或密码不正确。
运维·服务器
盗理者1 小时前
AI Agent 技能分享|SQL 性能诊断与优化
java·sql·spring·skill
GitLqr1 小时前
Java 26 终于原生支持 HTTP/3 了:告别 Netty,直接用 QUIC
java·netty·http3
用户40966601317511 小时前
Jackson 序列化:@JsonIgnore / @JsonProperty / @JsonFormat / @JsonInclude / @JsonUnwrapped 一次讲清楚
java·后端
码路漫漫1 小时前
用了 Caffeine,消息为什么还是被处理了两次?
java