用 journalctl 只看本次开机的错误日志

按优先级过滤 systemd 日志,只显示本次启动以来的错误及更严重级别的消息,包含时间戳、单元名和完整内容。

Linux系统终端诊断低风险
执行 journalctl -p err -b --no-pager,即可列出本次开机以来所有错误级别(priority 3)及以上的日志。

01命令

命令
$ journalctl -p err -b --no-pager

02作用说明

-p err 按日志优先级过滤,err 对应优先级 3,journalctl 会同时包含更严重的 crit、alert、emerg 级别,因为过滤条件匹配的是下限。-b 表示只看本次开机;用 -b -1 可查看上一次开机,去掉 -b 则检索所有保留的日志。去掉 --no-pager 可进入交互式翻页,再加 -u nginx.service 可只看某个服务。用 journalctl --disk-usage 可查看日志占用的磁盘空间。

03风险

风险低风险
使用条件On many distros you must be in the 'systemd-journal', 'adm', or 'wheel' group (or use sudo) to see all system units' logs
!注意: 查看日志很安全,但不要手动删除日志文件——请使用 journalctl --vacuum-size 或 --vacuum-time 来清理空间。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • journalctl(1) — Query the systemd journal
    Ubuntu manpages · vendor-doc · 2026-09-17
    依据: The manual documents '-p' / '--priority=' to filter by message priority (e.g. err) and '-b' / '--boot' to limit output to a specific boot.
  • systemd/Journal - ArchWiki
    Arch Linux Wiki · community · 2026-09-17
    依据: The ArchWiki journal page shows filtering journalctl output by priority level and by current boot with examples like journalctl -p err -b.

最后验证: 2026-09-17 · 分类: 系统与设置

06相关方案