LLI Wiki — My Digital Knowledge Base

systemd unit file specifiers

Short reference of the % specifiers usable in systemd unit files: names, instances, host, user and directories.

systemd unit files accept specifiers: placeholders written as % followed by a letter. systemd replaces them when the unit is loaded, so one unit file can work on several machines or for several instances. This is a short reference; the full list is in the systemd.unit(5) manual.

# Illustrative example: %S is the state directory root
ExecStart=/usr/bin/myservice --state-dir %S/myservice

Unit names and instances

Specifier Meaning
%n Full unit name, including the suffix (for example myservice@web.service)
%N Unit name without the suffix
%p Prefix name (myservice for myservice@web.service)
%i Instance name: the text between the first @ and the suffix (web)
%I Instance name with escaping removed
%j Last part of the prefix, after the last -
%f Unescaped file name, with a leading / added

Host and system

Specifier Meaning
%H Host name
%l Short host name (up to the first dot)
%q Pretty host name from /etc/machine-info, or the short host name if not set
%m Machine ID
%b Boot ID, which changes at each boot
%v Kernel release, as printed by uname -r
%a Architecture, for example x86-64 or arm64
%o, %w, %W OS ID, version ID and variant ID from /etc/os-release
%A, %B, %M OS image version, build ID and image ID from /etc/os-release (empty if not set)

User and directories

The values of these specifiers depend on whether the unit runs under the system manager or a user manager. Under the system manager, the user and group are root and 0.

Specifier Meaning
%u, %U User name and numeric UID of the service manager's user
%g, %G Group name and numeric GID of the service manager's user
%h Home directory of that user
%s Login shell of that user
%t Runtime directory root (/run, or $XDG_RUNTIME_DIR for user managers)
%S State directory root (/var/lib, or the user equivalent)
%C Cache directory root (/var/cache, or the user equivalent)
%L Log directory root (/var/log, or the user equivalent)
%E Configuration directory root (/etc, or the user equivalent)
%T Temporary directory (/tmp)
%V Larger, persistent temporary directory (/var/tmp)
%d Credentials directory (from $CREDENTIALS_DIRECTORY)

Other

Specifier Meaning
%y Path of the unit file that defines the unit
%Y Directory of that unit file
%% A literal percent sign

Notes

Mastodon LLIMastodon SocialFosstodon