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
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.
-
ZorinOS 17.1 Released, Includes Improved Windows App Support
If you need or desire to run Windows applications on Linux, there's one distribution intent on making that easier for you and its new release further improves that feature.
-
Linux Market Share Surpasses 4% for the First Time
Look out Windows and macOS, Linux is on the rise and has even topped ChromeOS to become the fourth most widely used OS around the globe.
-
KDE’s Plasma 6 Officially Available
KDE’s Plasma 6.0 "Megarelease" has happened, and it's brimming with new features, polish, and performance.
-
Latest Version of Tails Unleashed
Tails 6.0 is based on Debian 12 and includes GNOME 43.
-
KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.
-
Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.