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)


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.

  • 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? – Gabriel Southern Nov 12 '15 at 19:58
  • @GabrielSouthern it's a bug. :D – muru Nov 12 '15 at 20:06

Looks like, that the asterisk must be shell escaped

# systemctl stop sshd@\\*.service
  • This is the answer, with a tweak. First - how utterly silly... having to escape the pattern. Anyway, only one '\' is needed: systemctl list-units ntp\*. – Jon Sep 26 '18 at 20:05
  • 2
    @Jon it needs to be escaped because the line must first be interpreted by your shell, which likely performs file globbing against the current directory path. – vintnes Jul 7 '20 at 16:56

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.