当前位置:网站首页>View log common commands
View log common commands
2022-08-09 07:05:00 【Anakin6174】
1. Common commands for viewing logs
tail:
-n is to display the line number; it is equivalent to the nl command; examples are as follows:
tail -100f test.log Real-time monitoring of 100 lines of logs
tail-n 10 test.log Query the log of the last 10 lines at the end of the log;
tail -n +10 test.log Query all logs after 10 lines;head:Contrary to tail, tail is how many lines of log to look after; an example is as follows:head -n 10 test.log Query the first 10 lines of logs in the log file;head -n -10 test.log Query the log file for all logs except the last 10 lines;cat:tac is the reverse order view, which is the reverse of the cat word; examples are as follows:cat -n test.log |grep "debug" query the log of keywords
Application scenario 1: View by line number - filter out logs near keywords
1) cat -n test.log |grep "debug" to get the line number of the key log
p>2) cat -n test.log |tail -n +92|head -n 20 Select the middle line where the keyword is located. Then view the log of the first 10 lines and the last 10 lines of the keyword:
tail -n +92 means query the log after 92 lineshead -n 20 means to check the first 20 records in the previous query results
Scenario 2: Query logs by date
sed -n '/2014-12-17 16:17:20/,/2014-12-17 16:17:36/p' test.log
Special note: The above two dates must be the logs printed in the log, otherwise they are invalid;
grep '2014-12-17 first16:17:20' test.log to determine if this time point is in the log
4. Application scenario 3: The log content is very large, and it is inconvenient to print it on the screen
(1) Use the more and less commands,
Such as: cat -n test.log |grep "debug" |more This will print in pages, turn pages by clicking the space bar(2) Use >xxx.txt to save it to a file, then you can pull down this file for analysisSuch as: cat -n test.log |grep "debug" >debug.txt
- Scenario
There is a large log file of dozens of meters, and the records in it are sorted by time.Now need to find an error message in it, I don't know where.At this time, it is difficult to copy the content. Even if it is copied, it is difficult for a general editor to hold such a large file.At this time, using less can solve this problem very easily and conveniently.
Using
The first is to open the file: less fileName.log
ctrl + f, look at the time, and turn to the next page.
If you feel that the information is too low, you can skip to the last line of the log file: shift+g
Then, ctrl+b to go to the previous page to view page by page
If you know the keywords, you can still search, press '/' and enter the words you want to search, and all the keywords will be highlighted.It is very convenient to find.
边栏推荐
- stm32定时器之简单封装
- 排序第四节——归并排序(附有自己的视频讲解)
- The Integer thread safe
- Classes and Structures
- 虚拟机网卡报错:Bringing up interface eth0: Error: No suitable device found: no device found for connection
- C语言的内置宏(定义日志宏)
- The working principle of the transformer (illustration, schematic explanation, understand at a glance)
- SAP ALV 数据导出被截断的bug
- failed (13: Permission denied) while connecting to upstream
- 常见的分布式事务解决方案
猜你喜欢
分布式id 生成器实现
SAP ALV data export many of the bugs
Zero shift of leetcode
排序第三节——交换排序(冒泡排序+快速排序+快排的优化)(5个视频讲解)
虚拟机网卡报错:Bringing up interface eth0: Error: No suitable device found: no device found for connection
分布式理论
【修电脑】系统重装但IP不变后VScode Remote SSH连接失败解决
Inception V3 Eye Closure Detection
学习小笔记---机器学习
【报错】Root Cause com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
随机推荐
错误:为 repo ‘oracle_linux_repo‘ 下载元数据失败 : Cannot download repomd.xml: Cannot download repodata/repomd.
常用测试用例设计方法之正交实验法详解
物理层课后作业
leetcode 之盛水问题
Lottie系列四:使用建议
rsync:recv_generator: mkdir (in backup) failed:Permission denied (13) |failed to set times on '.'
找不到和chrome浏览器版本不同的chromedriver的解决方法
makefile记录
vlucas/phpdotenv phpdotenv获取变量内容偶尔出现返回false
Transaction concluded
Built-in macros in C language (define log macros)
P1505 [国家集训队]旅游 树链剖分
单例 DCL(double check lock) 饱汉模式和饿汉模式
用tensorflow.keras模块化搭建神经网络模型
2022 年全球十大最佳自动化测试工具
HDU - 3183 A Magic Lamp 线段树
2022年7月小结
The JVM thread state
2017 G icpc shenyang Infinite Fraction Path BFS + pruning
学习小笔记---机器学习