Post

Systemd Cheat Sheet

Systemd Cheat Sheet

Systemd is a suite of fundamental building blocks for a Linux system. It provides a system and service manager that runs as PID 1 and initializes the rest of the system. It is replacement to SysV in most modern Linux distributions.

Key Features

  • Parallel startup of services.
  • On-demand activation of daemons.
  • Dependency-based service control.

Basic System Control

Get system status

1
systemctl status

Reboot the system

1
systemctl reboot

Power off the system

1
systemctl poweroff

Suspend the system

1
systemctl suspend

Hibernate the system

1
systemctl hibernate

Mixed sleep (hybrid sleep)

1
systemctl hybrid-sleep

List all units

1
systemctl list-units

List all active units

1
systemctl list-units --state=active

List all failed units

1
systemctl list-units --state=failed

Service Management

Start a service

1
systemctl start <serviceName>.service

Stop a service

1
systemctl stop <serviceName>.service

Restart a service

1
systemctl restart <serviceName>.service

Reload a service’s configuration (without full restart)

1
systemctl reload <serviceName>.service

Get the status of a service

1
systemctl status <serviceName>.service

Check if a service is enabled to start on boot

1
systemctl is-enabled <serviceName>.service

Enable a service to start on boot

1
systemctl enable <serviceName>.service

Disable a service from starting on boot

1
systemctl disable <serviceName>.service

Mask a service (prevent it from being started)

1
systemctl mask <serviceName>.service

Unmask a service (allow it to be started)

1
systemctl unmask <serviceName>.service

Service Dependencies

Show a unit’s dependencies

1
systemctl list-dependencies <serviceName>.service

Unit Files

Show the location of a unit file

1
systemctl show <serviceName>.service -p FragmentPath

Edit a unit file

1
systemctl edit <serviceName>.service

Example:

1
2
3
# Set the EDITOR at runtime
# `--full`: Edit the main unit file instead of creating a snippet.  
EDITOR=vim systemctl edit apache2.service --full

Show the contents of a unit file

1
systemctl cat <serviceName>.service

Reload systemd’s unit files

1
systemctl daemon-reload

Journal Control (Logging)

Journalctl is a command-line utility that allows you to view and query logs stored in the systemd journal. The journal is a structured, binary log format that collects logs from various sources, including the kernel, system services, and applications.

Show all logs

1
journalctl

Show logs for a specific service

1
journalctl -u <serviceName>.service

Show logs from boot

1
journalctl -b

Follow logs in real-time

1
journalctl -f

Show recent logs (e.g., last 10 minutes)

1
journalctl --since "10 min ago"

Show logs since a specific time

1
journalctl --since "2025-03-15"

Show logs until a specific time

1
journalctl --until "2025-03-15 12:00:00"

Show logs within a time range

1
journalctl --since "yesterday" --until "now"

Show kernel logs

1
journalctl -k

Show logs and with explanations

1
journalctl -x

Disk Usage

Show journal disk usage

1
journalctl --disk-usage

Time Synchronization

Check the status of the time synchronization service

1
systemctl status systemd-timesyncd.service

Other Useful Commands

Show system uptime

1
uptime

Show current system limits

1
ulimit -a

Conclusion

I find this systemd cheat sheet incredibly useful for managing systems and services in Linux. It serves as a quick reference for the common tasks I handle daily. While systemd offers a wide range of features and options, this cheat sheet helps me easily recall essential commands, which significantly enhances my workflow. For more detailed information, I often refer to the official systemd documentation or use the man systemd command.

This post is licensed under CC BY 4.0 by the author.