1、实时监控日志
tail -f test.log
2、实时监控当前100行日志
tail -100f test.log
3、查看最新的100行日志(-n表示显示行号)
tail -n 100 test.log
4、查看除了头100行以外的所有日志
tail -n +100 test.log
5、查看头100行日志
head -n 100 test.log
6、查看除了最后100以外的所有日志
head -n -100 test.log
7、正序查找日志中的关键字
cat -n test.log | grep "exception"
ps:如果查到的日志很多,可以使用more进行分页
cat -n test.log | grep "exception" | more
8、获取到了关键字的行号,要查看行号附近日志,比如要查看行号为100附近的日志
cat -n test.log | grep "exception" | tail -n +90 |head -n 20
ps:cat -n test.log | grep "exception" | tail -n +90 展示的是90行以后的所有日志
ps:后面再跟上head -n 20 表示在前面的基础上只查看前20条日志,相当于查看90~110之间的日志
9、倒叙查找关键字日志
tac -n test.log | grep "exception"
10、将日志保存到文件中
cat -n test.log | grep "exception" > test.txt
11、定位到日志结尾
shift + g
12、从下往上查找
shift + n
13、根据日期查询日志
sed -n '/2019-07-26 11:12:05.842/,/2019-07-26 11:12:05.901/p' htjf-account-web.log
ps:查询的日期在日志中要有