journalctl
进程与系统
用法
journalctl -u <unit> [-f]读取 systemd 以二进制格式收集的日志;没有 /var/log/journal 时日志一重启就没了,而 `-u` 要写单元的准确名字。
常用选项
| 选项 | 含义 |
|---|---|
| -u <unit> | Only one unit. The name must match exactly. |
| -f | Follow new lines as they arrive, like tail -f. |
| -n 100 | The last 100 lines instead of the whole journal. |
| --since "1 hour ago" | Limit by time; --until does the other end. |
| -p err | Only this priority and worse (emerg, alert, crit, err, warning...). |
| -b / -b -1 | This boot only / the previous boot. |
| -k | Kernel messages only. |
| --no-pager | Print straight to stdout so you can pipe it. |
示例
journalctl -u nginx -n 50 --no-pagerThe last fifty lines from one service.
journalctl -fu myappWatch a service live while you reproduce a bug.
journalctl --since "10 min ago" -p errOnly recent errors, from every unit.
看什么在跑、什么在吃机器。先弄清是什么,再决定杀不杀。
怎么看
- 方括号 [ ] 表示这部分可以不写。
- 省略号 … 表示可以写多个。
- 选项区分大小写——有些命令里 -r 和 -R 不是一回事。
常见问题
Q. journalctl 是做什么的?
读取 systemd 以二进制格式收集的日志;没有 /var/log/journal 时日志一重启就没了,而 `-u` 要写单元的准确名字。
Q. 怎么写?
journalctl -u <unit> [-f] —— 方括号表示可以省略的部分。
Q. 值得记的选项有几个?
这里列了 8 个,完整列表在 man journalctl。这条命令属于进程与系统。
相关命令
man 手册: man journalctl