linux命令--日志
1、时段日志:
命令: sed -n '/2021-12-08 16:00:00/,/2021-12-08 17:00:00/p' nohup.out
注:需要日志中有对应的时间,否则查不到
命令: sed -n '/2021-12-08 16*/,/2021-12-08 17*/p' nohup.out
注:模糊查询,避免日志中没有对应的时间
命令: grep '2021-12-08 17:[00-22]' nohup.out
注:正则匹配搜索
2、结合grep:
命令: sed -n '/2021-12-08 16*/,/2021-12-08 17*/p' nohup.out | grep post
注:查询时间段内带有post的日志行
3、日志导出:
命令:sed -n '/2021-12-08 16*/,/2021-12-08 17*/p' nohup.out > yoyo.log
注:日志导出为yoyo.log
4、日志查看:
tail -n 10 nohup.out 查询最后10行
tail -f nohup.out 监视文件增长(尾部内容、默认10行)
head -n 10 nohup.out 查询开始10行
cat -n nohup.out 给日志添加行号
cat -n nohup.out | grep post 含有post的日志添加行号
sed -n '3100,3129p' nohup.out 按行数截取
more nohup.out 分页查看日志 space 下一页 b上一页 Enter 下一行 q退出
less nohup.out 分页查看日志 pagedown下一页 pageup上一页 q退出

浙公网安备 33010602011771号