journalctl

プロセスとシステム

書き方

journalctl -u <unit> [-f]

systemd がバイナリ形式でためたログを読みます。/var/log/journal がなければ再起動でログは消え、`-u` にはユニット名を正確に書く必要があります。

よく使うオプション

オプション意味
-u <unit>Only one unit. The name must match exactly.
-fFollow new lines as they arrive, like tail -f.
-n 100The last 100 lines instead of the whole journal.
--since "1 hour ago"Limit by time; --until does the other end.
-p errOnly this priority and worse (emerg, alert, crit, err, warning...).
-b / -b -1This boot only / the previous boot.
-kKernel messages only.
--no-pagerPrint straight to stdout so you can pipe it.

journalctl -u nginx -n 50 --no-pager

The last fifty lines from one service.

journalctl -fu myapp

Watch a service live while you reproduce a bug.

journalctl --since "10 min ago" -p err

Only 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