journalctl 用来查询 systemd-journald 服务收集到的日志。systemd-journald 服务是 systemd init 系统提供的收集系统日志的服务。
查询指定unit的log:journalctl -u xxxx查询指定时间的log:
# 查看当前时间并指定格式 date "+%Y-%m-%d %H:%M:%S" # 指定开始时间 journalctl --since="2021-08-21 10:23:12" # 指定结束时间 journalctl --until="2021-08-21 10:23:12" # 指定一段时间 journalctl --since="2021-08-21 10:23:11" --until="2021-08-21 10:23:15" # 指定一段时间以内的log... journalctl --since="1 minute ago" journalctl --since="30 minute ago" journalctl --since="1 hour ago"查询指定行数的Log:
journalctl -u toby --lines=10反向输出:
journalctl -u toby --lines=10 -r结合grep命令实现过滤:
# 简单grep关键字 journalctl -u xxxx |grep ping # 使用正则表达式进行自定义的grep journalctl -u xxxx |grep -E "Ad+B"使用tail来实时查询syslog:
tail -f /var/log/syslog



