systemd and journalctl Cheat Sheet¶
Reference sheet for managing systemd services and inspecting system logs with journalctl.
Systemd is the system and service manager responsible for controlling system units, background services, boots, and logs.
1. Service Management (systemctl)¶
Check Service Status:
Start Service:
Stop Service:
Restart Service:
Reload Config without Restart:
Reload or Restart (Fallback):
Enable on Boot & Start Immediately:
Disable on Boot & Stop Immediately:
Mask Unit (Prevent manual/auto start):
Unmask Unit:
2. State & Unit Inspection¶
Check if Active:
Check if Enabled on Boot:
Check if Unit Failed:
List All Active Services:
List All Installed Unit Files:
List All Failed Units:
View Unit File Contents:
Show Low-Level Unit Properties:
3. Unit File Editing & Lifecycle¶
Reload Manager (After file changes):
Create Override/Drop-in Config:
Edit Complete Unit File Copy:
Remove Override/Drop-in Config:
4. Log Filtering & Diagnostics (journalctl)¶
Basic & Real-Time Logs¶
Follow Unit Logs Real-Time:
View Last N Lines for Unit:
View Current Boot Logs:
View Previous Boot Logs:
List All Available Boots:
View Kernel Logs (dmesg equivalent):
Time & Priority Filtering¶
Filter by Relative Time:
Filter by Absolute Time Range:
Filter by Priority Level:
Filter by Process ID:
Filter by Executable Path:
Formatting & Disk Space Maintenance¶
Raw Message Output (No metadata):
Pretty JSON Output:
Check Total Journal Disk Usage:
Trim Storage by Size Limit:
Trim Storage by Retention Period:
5. Boot Analysis & Performance (systemd-analyze)¶
Check Startup Duration Breakdown:
List Slowest Initializing Services:
Print Boot Time Dependency Tree:
Analyze Unit Security Hardening:
6. User-Level Services (--user)¶
User services operate without sudo under ~/.config/systemd/user/.
Check User Service Status:
Start User Service:
Enable User Service:
View User Service Logs:
Persist User Services After Logout:
7. System State & Targets¶
View Current Default Target:
Set Default to Multi-User (CLI):
Set Default to Graphical (GUI):
Switch Target without Rebooting:
Reboot System:
Power Off System:
8. Reference Unit File Template¶
# /etc/systemd/system/example.service
[Unit]
Description=Example Custom Background Service
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=nobody
Group=nobody
ExecStart=/usr/local/bin/example-daemon --config /etc/example.conf
Restart=on-failure
RestartSec=5s
# Basic Security Sandboxing
ProtectSystem=full
ProtectHome=true
NoNewPrivileges=true
[Install]
WantedBy=multi-user.target