当前位置:网站首页>查看日志常用命令
查看日志常用命令
2022-08-09 06:56:00 【Anakin6174】
1.查看日志常用命令
tail:
-n 是显示行号;相当于nl命令;例子如下:
tail -100f test.log 实时监控100行日志
tail -n 10 test.log 查询日志尾部最后10行的日志;
tail -n +10 test.log 查询10行之后的所有日志;
head:
跟tail是相反的,tail是看后多少行日志;例子如下:
head -n 10 test.log 查询日志文件中的头10行日志;
head -n -10 test.log 查询日志文件除了最后10行的其他所有日志;
cat:
tac是倒序查看,是cat单词反写;例子如下:
cat -n test.log |grep "debug" 查询关键字的日志
应用场景一:按行号查看—过滤出关键字附近的日志
1)cat -n test.log |grep “debug” 得到关键日志的行号
2)cat -n test.log |tail -n +92|head -n 20 选择关键字所在的中间一行. 然后查看这个关键字前10行和后10行的日志:
tail -n +92表示查询92行之后的日志 head -n 20 则表示在前面的查询结果里再查前20条记录
应用场景二:根据日期查询日志
sed -n ‘/2014-12-17 16:17:20/,/2014-12-17 16:17:36/p’ test.log
特别说明:上面的两个日期必须是日志中打印出来的日志,否则无效;
先 grep '2014-12-17 16:17:20' test.log 来确定日志中是否有该 时间点
4.应用场景三:日志内容特别多,打印在屏幕上不方便查看
(1)使用more和less命令,
如: cat -n test.log |grep "debug" |more 这样就分页打印了,通过点击空格键翻页
(2)使用 >xxx.txt 将其保存到文件中,到时可以拉下这个文件分析
如:cat -n test.log |grep "debug" >debug.txt
- 场景
有一个几十m的大日志文件,里边的记录是按时间排序的。 现在需要找到其中,不知道在什么位置的一条错误消息。这时候,想把内容拷出来都费劲,就算拷出来了,一般的编辑器也难以hold住这么大的文件。这时候,用less,就能很简单方便的解决这个问题。
使用
首先是打开文件: less fileName.log
ctrl + f,看着时间,往下一页一页的翻。
如果 觉得信息偏下,可以跳到日志文件的最后一行:shift+g
然后,ctrl+b往上一页一页翻页查看
如果知道关键词还可以搜索,按 ‘/’ 之后输入要搜索的词,就会把所有的关键词高亮了。找起来十分的方便。
边栏推荐
- 【Shell】查找进程的pid并根据pid获取该进程所占用的端口号以及该进程在系统中所下达的指令名称
- ByteDance Written Exam 2020 (Douyin E-commerce)
- P6 ali machine test of 2020 Fibonacci number
- crc calculation
- vim 程序编辑器的基本操作(积累)
- imageio读取.exr报错 ValueError: Could not find a backend to open `xxx.exr‘ with iomode `r`
- Teach you how to make the Tanabata meteor shower in C language - elegant and timeless (detailed tutorial)
- MongDb query method
- SIGINT, SIGKILL, SIGTERM signal difference, summary of various signals
- Altium designer软件常用最全封装库,包含原理图库、PCB库和3D模型库
猜你喜欢
C语言实现顺序栈和链队列
The solution that does not work and does not take effect after VScode installs ESlint
01 自然语言处理NLP介绍
INSTALL_RPATH and BUILD_RPATH problem in CMake
longest substring without repeating characters
【报错】Root Cause com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
jvm线程状态
使用百度EasyDL实现智能垃圾箱
pycharm环境包导入到另外一个环境
Leetcode 70 stairs issues (Fibonacci number)
随机推荐
stm32定时器之简单封装
leetcode 之 70 爬楼梯问题 (斐波那契数)
P7阿里面试题2020.07 之滑动窗算法(阿里云面试)
线程的6种状态
分布式id 生成器实现
95后,刚工作2-3年就年薪50W+ ,才发现打败我们的,从来不是年龄···
dp学习笔记
mysql summary
Distributed id generator implementation
jvm线程状态
XILINX K7 FPGA+RK3399 PCIE驱动调试
排序第二节——选择排序(选择排序+堆排序)(两个视频讲解)
shardingsphere数据分片配置项说明和示例
VS2019 common shortcut keys
2022.8.8DAY628
leetcode 之盛水问题
图论,二叉树,dfs,bfs,dp,最短路专题
6 states of a thread
The AD in the library of library file suffix. Intlib. Schlib. Pcblib difference
crc calculation