12

The man page for systemctl says:

Unit Commands

list-units [PATTERN...] List known units (subject to limitations specified with -t). If one or more PATTERNs are specified, only units matching one of them are shown.

This is the default command.

My question is what does it mean by [PATTERN].

When I execute systemctl list-units I get relatively long list of the loaded units. But if I add a third argument I get an error message Too many arguments. So I am curious as to what parameters are valid for the [PATTERN] argument listed in the man page.

(I'm running Arch Linux and have version 227 of systemd)

3 Answers 3

13

From the same page:

Parameter Syntax

Unit commands listed above take either a single unit name (designated as NAME), or multiple unit specifications (designated as PATTERN...). In the first case, [...]

In the second case, shell-style globs will be matched against currently loaded units; literal unit names, with or without a suffix, will be treated as in the first case. This means that literal unit names always refer to exactly one unit, but globs may match zero units and this is not considered an error.

Glob patterns use fnmatch(3), so normal shell-style globbing rules are used, and "*", "?", "[]" may be used. See glob(7) for more details. The patterns are matched against the names of currently loaded units, and patterns which do not match anything are silently skipped. For example:

# systemctl stop sshd@*.service

will stop all sshd@.service instances.

3
  • What result do you see if you type systemctl list-units sshd@*.service? I get Too many arguments.. Maybe a bug in my version of systemctl? Nov 12, 2015 at 19:58
  • @GabrielSouthern it's a bug. :D
    – muru
    Nov 12, 2015 at 20:06
  • Seems to work for stop but not for disable :c Says Failed to disable unit: Unit file uds_@\x2a.service does not exist.
    – Hi-Angel
    May 14, 2021 at 8:23
3

Looks like the asterisk must be shell escaped

# systemctl stop sshd@\*.service
0
0

I'm getting this error in version systemd 247 (247.7-1-manjaro):

$ systemctl list-units sshd@\*.service
  UNIT LOAD ACTIVE SUB DESCRIPTION
0 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.

Any ideas?

1
  • This is not an error, it just doesn't find any matching service units. On our Linux systems (mostly Ubuntu), services do not have @ in their names, and systemctl list-units sshd\*.service does list the sshd service. Jun 10, 2021 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.