2021-07-21 08:28:07 +00:00
|
|
|
:PROPERTIES:
|
|
|
|
:ID: 941e0a85-1bb4-45be-a729-1b577c7ee317
|
|
|
|
:END:
|
2021-06-20 02:22:13 +00:00
|
|
|
#+title: Command line: journalctl
|
2021-05-21 04:09:51 +00:00
|
|
|
#+date: "2021-05-20 23:07:39 +08:00"
|
2021-10-09 10:14:46 +00:00
|
|
|
#+date_modified: "2021-09-01 22:39:16 +08:00"
|
2021-05-21 04:09:51 +00:00
|
|
|
#+language: en
|
|
|
|
#+property: header-args :results none
|
|
|
|
|
|
|
|
|
2021-08-27 14:24:00 +00:00
|
|
|
The logging daemon of systemd (see [[id:d83c099a-fc11-4ccc-b265-4de97c85dcbe][systemd-journald]]).
|
2021-05-21 04:09:51 +00:00
|
|
|
Not only it can view your logs, you can ask to view specific logs and delete some of them.
|
|
|
|
|
|
|
|
For more information, see =journalctl.1= manual page.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* Options
|
|
|
|
|
2021-10-09 10:14:46 +00:00
|
|
|
- =-b, --boot [ID][+OFFSET]= shows the logs starting from given boot time (or current boot if empty).
|
|
|
|
- =-e, --pager-end= to go to the end of the logs.
|
|
|
|
- =-f, --follow= watches the logs.
|
|
|
|
- =-k, --dmesg= prints the logs from the kernel.
|
|
|
|
- =--list-boots= prints a list of boots useful for knowing the boot logs from =-b=.
|
|
|
|
- =--user-unit= shows logs from a user unit.
|
|
|
|
- =-u, --unit [UNIT]= shows the logs of a system unit.
|
|
|
|
- =--vacuum-time [TIMESPAN]= deletes logs older than the specified timespan [fn:: View =systemd.time.5= for more information.].
|
|
|
|
- =-x, --catalog= prints helpful messages such as the documentation URIs.
|
2021-05-21 04:09:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* Examples
|
|
|
|
|
|
|
|
This tool is already comprehensive.
|
|
|
|
Needs a comprehensive database of examples to fight against this scope.
|
|
|
|
|
|
|
|
|
|
|
|
** Watch the logs from a specific unit at boot time
|
|
|
|
|
2021-05-30 13:33:19 +00:00
|
|
|
#+begin_src
|
2021-05-21 04:09:51 +00:00
|
|
|
journalctl --user-unit borgbackup.service -fb
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
|
|
|
|
** Delete the logs older than a month
|
|
|
|
|
2021-05-30 13:33:19 +00:00
|
|
|
#+begin_src
|
2021-05-21 04:09:51 +00:00
|
|
|
journalctl --vacuum-time=1m
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
|
|
|
|
** View the latest logs with helpful messages
|
|
|
|
|
2021-05-30 13:33:19 +00:00
|
|
|
#+begin_src
|
2021-05-21 04:09:51 +00:00
|
|
|
journalctl -xe
|
|
|
|
#+end_src
|
2021-10-09 10:14:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
** Get the logs of a service unit from 2 boots ago
|
|
|
|
|
|
|
|
#+begin_src
|
|
|
|
journalctl --boot -2 --user-unit borgbackup@personal-drive.service
|
|
|
|
#+end_src
|