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