Using basic systemd commands
Control Plan

Systemd is a complex management structure with many commands and capabilities. We provide an overview of a few basic commands and their use.
One of the criticisms of systemd, the new system management framework [1], is that it is a monolithic structure that violates the time-honored Unix principle of using small, dedicated tools. However, when you examine it, systemd proves less monolithic than it sounds. Instead, it has introduced a series of new tools for system administration, each of which has its own specific purpose.
What gives systemd a monolithic appearance is that its structure is consistent throughout. Users can be confident that a file ending in "ctl" is a command, whereas one ending in "conf" is a configuration file. Even more importantly, each command has the same structure:
COMMAND SUB-COMMAND OPTIONS
Often, options and sub-commands are the same for different commands.
Systemd tends to thoroughness, so it is impractical to list all of the main options and commands here. Instead, there is room only for some basic functions to give a sense of what each command can do. For more detailed information, consult each command's man page or the systemd documentation [2]. You can get a sense of the complexity of systemd from the fact that systemctl
, the most important systemd command, has a man page of 868 lines – more than four times as long as a command such as cp
or ls
. In this article, I'll describe some of the basic commands introduced by systemd.
Systemctl
Systemctl is systemd's main command. It manages units, which are the files to manage system resources. Units are organized into control groups, such as service, socket, device, mount, automount, and snapshot, which stores an image of the current state of systemd for later restoration. These control groups are used as an extension for unit files, so you always know which control group a unit belongs to. A system can have between 150 and 300 units, depending on its setup and what it runs. Usually, systems that run Gnome technologies have more units than KDE, possibly because systemd was initially developed with Gnome in mind.
The systemctl
command manages units – enabling and disabling them, changing their state, and managing positive dependencies (what must be present for a unit to operate) and reverse dependencies (what cannot be present for a unit to operate). This broad array of controls makes systemctl
extremely powerful – and, therefore, potentially capable of crashing your machine if used carelessly.
You can use --all
(-a
) to see a list of units as you compose the command structure (Figure 1). To avoid unintended consequences, whenever possible, add the option --type=
(-t
), to limit the command to particular control groups such as sockets or service, --state=
, to specify whether units whose state is LOAD, SUB, or ACTIVE are affected, or both options. Use the command list-dependencies
to view a unit's dependencies, and the --reverse
option to list a unit's reverse dependencies.
Most of systemctl's basic functions are in its commands. With show
and status
, you can read current information about a unit or a comma-separated list of units. The start
and stop
commands activate a unit, whereas
set-property UNIT-NAME PARAMETER SETTING
edits a unit's definition.
Journalctl
Journals are one the more controversial features of systemd, because they are binary files rather than the traditional text files generally used in Linux. However, in compensation, the journalctl
command has a thorough selection of choices for viewing logs.
Many distributions do not ship with systemd's journal enabled, so check to see if your installation has a /var/log/journal
file. If not, you can set it up with the command:
setfacl -R -nm g:adm:rx,d:g:adm:rx /var/log/journal
You should also edit /etc/systemd/journald.conf
, using the settings storage=persistent
to save the journal permanently and SystemMaxFileSize = 100M
so that the journal does not grow too large.
The bare command displays the journal, oldest entry first (Figure 2). However, for convenience, consider adding the option --output=verbose
so that information is not cut off and --reverse
(-r
) so that the oldest entry is first.
You can filter journal messages with --dmesg
(-k
) to view only messages from the kernel, with --system
for messages from system services, or with --PID=
to view messages from a particular service. If you want to view messages from a particular book, run journalctl
with --system-boots
, then use the identifier in the second field of the output to run the records for the boot you want to examine. Alternatively, you can use line=NUMBER
to view only a set number of events or use --since
or --until
to set a range of dates or times.
Halt, Poweroff, Reboot, Shutdown
These commands all close down the system. Technically, halt
closes down the system without turning the power off, whereas poweroff
and shutdown
do turn the power off, and reboot
does a cold reboot. However, all four commands include the options --poweroff
and --reboot
, so any distinction is blurred.
The shutdown
command is unique in that options may be followed by a time to activate the command. The time is in hh:mm format, using a 24-hour clock. You also have the option of specifying a time in the future by specifying a number of minutes with a plus sign as a prefix. If no time is specified, then the default is +1
. Using +0
runs the command immediately. At the end of a shutdown command with a time argument, you can use the wall
command to broadcast a message to all users.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.
News
-
Fedora 39 Beta is Now Available for Testing
For fans and users of Fedora Linux, the first beta of release 39 is now available, which is a minor upgrade but does include GNOME 45.
-
Fedora Linux 40 to Drop X11 for KDE Plasma
When Fedora 40 arrives in 2024, there will be a few big changes coming, especially for the KDE Plasma option.
-
Real-Time Ubuntu Available in AWS Marketplace
Anyone looking for a Linux distribution for real-time processing could do a whole lot worse than Real-Time Ubuntu.
-
KSMBD Finally Reaches a Stable State
For those who've been looking forward to the first release of KSMBD, after two years it's no longer considered experimental.
-
Nitrux 3.0.0 Has Been Released
The latest version of Nitrux brings plenty of innovation and fresh apps to the table.
-
Linux From Scratch 12.0 Now Available
If you're looking to roll your own Linux distribution, the latest version of Linux From Scratch is now available with plenty of updates.
-
Linux Kernel 6.5 Has Been Released
The newest Linux kernel, version 6.5, now includes initial support for two very exciting features.
-
UbuntuDDE 23.04 Now Available
A new version of the UbuntuDDE remix has finally arrived with all the updates from the Deepin desktop and everything that comes with the Ubuntu 23.04 base.
-
Star Labs Reveals a New Surface-Like Linux Tablet
If you've ever wanted a tablet that rivals the MS Surface, you're in luck as Star Labs has created such a device.
-
SUSE Going Private (Again)
The company behind SUSE Linux Enterprise, Rancher, and NeuVector recently announced that Marcel LUX III SARL (Marcel), its majority shareholder, intends to delist it from the Frankfurt Stock Exchange by way of a merger.