Systemd Cheatsheet

Systemd is an init system in Linux used for system intialization and service management. It is fairly useful to manage and monitor services. In this cheatsheet you will find a collection of common commands used with the command line tools systemctl and journalctl.

Managing Systemd

  • systemctl list-units list units and show if they are loaded and/or active
  • systemctl list-unit-files list unit files and what status they have (enabled/disabled/static/…)
  • systemctl list-dependencies list dependency tree
  • systemctl list-dependencies [SERVICE] list dependencies of a unit

Managing Services

  • systemctl status [SERVICE] check status of service
  • systemctl show [SERVICE] show service information
  • systemctl start [SERVICE] start service
  • systemctl stop [SERVICE] stop running service
  • systemctl restart [SERVICE] restart service
  • systemctl reload [SERVICE] reload service without stopping it
  • systemctl enable [SERVICE] enable service to start at boot
  • systemctl disable [SERVICE] disable service

Viewing Logs

  • journalctl View all logs
  • journalctl -u [SERVICE] see logs of a single service
  • journalctl -u [SERVICE] -u [SERVICE 2] see logs of more services
  • journalctl -u [SERVICE] -f follow the logs of a single service

Filter by time with:

  • journalctl --since "1 hour ago" entries logged in the last hour
  • journalctl --since "2 days ago" entries logged in the last two days
  • journalctl --since "2 days ago" --until "1 day ago" entries between two days ago and one day ago
  • journalctl --since "2020-01-01 00:00:00" --until "2020-01-05 12:30:00" entries between two dates

Output arguments:

  • -o short-iso show dates in ISO 8601 time format
  • -o short-iso-precise show dates in ISO 8601 time format including full microsecond precision
  • -o cat show only entries without timestamps
  • -o json show each entry formatted as JSON line
  • -o json-pretty display as pretty formatted JSON

Further arguments:

  • -b show entries since last boot
  • -r show entries in reverse chronological order
  • -n 50 show last 50 entries
  • --utc show timestamps in UTC time
  • --no-hostname don’t show hostname field

References

Image from Systemd