LPIC-1 Exam 101 free question 2 / 10 · Domain 1: System Architecture
On a systemd machine, you want to read from the journal only the messages recorded during the previous boot, not the current one. Which command do you run?
- journalctl -b 0
- journalctl -b 1
- journalctl -b -1
- journalctl -b all
Show the answer and explanation
Answer: C
Why this is correct
The -b (--boot) option of journalctl(1) restricts the output to the messages of a particular boot. When a number is given without a boot ID, a value of 0 or below counts from the end of the journal: -0 is the last boot and -1 is the one before it. The boot that is running now is the last boot in the journal, so the previous boot is addressed as -b -1.
Why the other options are wrong
"journalctl -b 1" … A positive number counts from the beginning of the journal, oldest first. 1 refers to the oldest boot kept in the journal, not the previous one. Forgetting the sign would show you a boot from an entirely different day.
"journalctl -b 0" … 0 counts from the end and means the last boot, which is the current boot. The result is the same as giving -b alone.
"journalctl -b all" … all is a special value that cancels an earlier -b filter, so the messages of every boot are shown.
Listing the boots
journalctl --list-boots lists the boots that remain in the journal, with the current one as 0 and earlier ones as -1, -2, and so on. Messages of earlier boots are readable if the journal is stored persistently, that is, under /var/log/journal/ (see --flush in journalctl(1)). For a machine that no longer boots, you can start from other media and point -D at that directory to read it.
Go to the LPIC-1 Exam 101 practice app (10 free questions; purchase unlocks all questions)