1、场景1: 按行号查看—-过滤出关键字附近的日志

  1. #基础命令
  2. tail -n 10 test.log 查询日志尾部最后10行的日志;
  3. tail -n +10 test.log 查询10行之后的所有日志;
  4. head -n 10 test.log 查询日志文件中的头10行日志;
  5. head -n -10 test.log 查询日志文件除了最后10行的其他所有日志;
  6. cat -n test.log |tail -n +92|head -n 20
  7. #cat -n test.log 查看日志
  8. #tail -n +92 从92行开始打印

2、场景2:那么按日期怎么查呢? 通常我们非常需要查找指定时间端的日志

  1. sed -n '/2019-12-18 18:00:09.675/,/2019-12-19 09:33:37.916/p' upload.log
  2. 注意:上面的两个日期必须是日志中打印出来的日志,否则无效.
  3. #翻页 more | less命令
  4. cat -n upload.log | grep "StorageException" | more
  5. #筛选处理,存到文件中
  6. cat -n upload.log | grep "StorageException" >> storageException.txt