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

相关推荐
Leighteen2 分钟前
`try-finally` 里的 `return`:为什么 `finally` 会悄悄改掉返回值、吞掉异常
java·开发语言
NiceCloud喜云26 分钟前
海外云服务器怎么选?适用场景、价格和避坑经验总结
运维·服务器
名字还没想好☜44 分钟前
Go 的 time.After 在 select 循环里内存泄漏:定时器堆积原理与 timer.Reset 正确姿势
java·数据库·golang·go·goroutine
easy_coder1 小时前
Linux LVM 知识文档
linux·运维
圆山猫1 小时前
[Virtualization](三):RISC-V H-extension 与 Guest 执行模式
android·java·risc-v
caishenzhibiao1 小时前
期货先行者主图 同花顺期货通指标
java·c语言·c#
史呆芬2 小时前
分布式事务实战:微服务跨服务数据一致性解决方案
java·后端·spring cloud
IT界的老黄牛2 小时前
限流命中后该怎么办:直接丢、阻塞等待、延迟重投三种姿势的取舍
java·rocketmq·redisson·令牌桶·削峰·分布式限流
小小的木头人2 小时前
Ubuntu 使用 udev + systemd + UUID 实现 USB 硬盘自动挂载
linux·运维·ubuntu
daad7773 小时前
记录matlab状态机demo
java·网络·matlab