当前位置:网站首页>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.
边栏推荐
猜你喜欢
随机推荐
MVN 中配置flyway mysq
分布式id 生成器实现
【Reprint】Deep Learning (deep learning) study notes arrangement
SAP ALV data export many of the bugs
如何 认识与学习BASH
Leetcode 70 stairs issues (Fibonacci number)
【MySQL】update mysql.user set authentication_string=password(“123456“) where User=‘root‘; 报错
list与string转换
Change Jupyter Notebook default open directory
日期处理,字符串日期格式转换
字节跳动笔试题2020 (抖音电商)
redis学习笔记
Example of using the cut command
长沙学院2022暑假训练赛(一)六级阅读
细谈VR全景:数字营销时代的宠儿
虚拟机网卡报错:Bringing up interface eth0: Error: No suitable device found: no device found for connection
线程池总结
2017.10.26模拟 b energy
【修电脑】系统重装但IP不变后VScode Remote SSH连接失败解决
jvm线程状态