Linux学习26-linux查看某个时间段的日志(sed -n)

前言

在linux上查找日志的时候,如果我想找出某个时间段的日志,比如查找今天早上8点到下午2点的日志。
用grep不太方便直接过滤出来,可以使用sed根据时间去查找
sed -n '/开始时间日期/,/结束时间日期/p' test.log

查找日志

比如下面这段日志,前面的时间格式都是类似2019-10-21 07:44:20

2019-10-21 07:44:20,408 [django.server:124] [basehttp:log_message] [INFO]- "GET /static/assets/img/logo.png HTTP/1.1" 200 11481
2019-10-21 07:44:20,437 [django.server:124] [basehttp:log_message] [INFO]- "GET /static/assets/img/loading.GIF HTTP/1.1" 200 63798
2019-10-21 07:44:20,447 [django.server:124] [basehttp:log_message] [INFO]- "GET /static/assets/img/bg.jpg HTTP/1.1" 200 135990
2019-10-21 07:44:53,971 [django.server:124] [basehttp:log_message] [INFO]- "GET /api/login/ HTTP/1.1" 200 3876
2019-10-21 07:44:53,997 [django.server:124] [basehttp:log_message] [INFO]- "GET /static/assets/iconfont/style.css HTTP/1.1" 200 1638
2019-10-21 07:44:54,010 [django.server:124] [basehttp:log_message] [INFO]- "GET /static/assets/img/main_bg.png HTTP/1.1" 200 2801
2019-10-21 07:44:54,035 [django.server:124] [basehttp:log_message] [INFO]- "GET /static/assets/iconfont/fonts/icomoon.ttf?u4m6fy HTTP/1.1" 200 6900
2019-10-21 07:44:59,361 [django.server:124] [basehttp:log_message] [INFO]- "POST /api/login/ HTTP/1.1" 302 0
2019-10-21 07:44:59,463 [django.server:124] [basehttp:log_message] [INFO]- "GET /api/index/ HTTP/1.1" 200 18447
2019-10-21 07:44:59,515 [django.server:124] [basehttp:log_message] [INFO]- "GET /static/assets/css/admin.css HTTP/1.1" 200 19660
2019-10-21 07:44:59,517 [django.server:124] [basehttp:log_message] [INFO]- "GET /static/assets/css/common.css HTTP/1.1" 200 1004
2019-10-21 07:44:59,518 [django.server:124] [basehttp:log_message] [INFO]- "GET /static/assets/js/app.js HTTP/1.1" 200 20844
2019-10-21 07:44:59,519 [django.server:124] [basehttp:log_message] [INFO]- "GET /static/assets/js/commons.js HTTP/1.1" 200 13209
2019-10-21 07:45:01,905 [django.server:124] [basehttp:log_message] [INFO]- "GET /api/add_module/ HTTP/1.1" 200 16422
2019-10-21 07:45:03,509 [django.server:124] [basehttp:log_message] [INFO]- "GET /api/project_list/1/ HTTP/1.1" 200 29

猜你喜欢

转载自www.cnblogs.com/yoyoketang/p/11729966.html
N!
n
N*
今日推荐