当前位置:网站首页>查看日志常用命令
查看日志常用命令
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往上一页一页翻页查看
如果知道关键词还可以搜索,按 ‘/’ 之后输入要搜索的词,就会把所有的关键词高亮了。找起来十分的方便。
边栏推荐
- mysql 总结
- shardingsphere数据分片配置项说明和示例
- Flask failed to create database without error
- 2017.10.26模拟 b energy
- 力扣 636. 函数的独占时间
- Introduction and use of BeautifulSoup4
- P6 ali machine test of 2020 Fibonacci number
- ByteDance Interview Questions: Mirror Binary Tree 2020
- 字节跳动笔试题2020 (抖音电商)
- codeforces Valera and Elections (这思维题是做不明白了)
猜你喜欢
Fragments
高项 03 项目立项管理
leetcode 之盛水问题
Fragments
install flask
分布式事务产生的原因
The working principle of the transformer (illustration, schematic explanation, understand at a glance)
Search 1688 product interface by image (item_search_img-search 1688 product by image (Politao interface) code docking tutorial
CMake中INSTALL_RPATH与BUILD_RPATH问题
找不到和chrome浏览器版本不同的chromedriver的解决方法
随机推荐
bzoj 5333 [Sdoi2018]荣誉称号
(本章节完结)排序第五节——非比较排序(计数排序+基数排序+桶排序)(附有自己的视频讲解)
线程池总结
半导体新能源智能装备整机软件系统方案设计
6 states of a thread
flask创建数据库失败未报错
排序第三节——交换排序(冒泡排序+快速排序+快排的优化)(5个视频讲解)
Error jinja2.exceptions.UndefinedError: 'form' is undefined
Common Oracle Commands
Service
db.sqlite3 has no "as Data Source" workaround
【MySQL】update mysql.user set authentication_string=password(“123456“) where User=‘root‘; 报错
vlucas/phpdotenv phpdotenv获取变量内容偶尔出现返回false
错误:为 repo ‘oracle_linux_repo‘ 下载元数据失败 : Cannot download repomd.xml: Cannot download repodata/repomd.
我入职阿里后,才知道原来简历这么写
【sqlite3】sqlite3.OperationalError: table addresses has 7 columns but 6 values were supplied
虚拟机网卡报错:Bringing up interface eth0: Error: No suitable device found: no device found for connection
ByteDance Interview Questions: Mirror Binary Tree 2020
物理层课后作业
String.toLowerCase(Locale.ROOT)