0

I want to get all service names which match a pattern.

This does not work:

systemctl list-units -t service --no-pager --no-legend| cut -d' ' -f1| grep mypattern

Long service names get cut.

Example:

fooo123@...abc-new.service

How can I list the whole unit name?

guettli
  • 3,591
  • 17
  • 72
  • 123

1 Answers1

2

You need to use the --full option:

Do not ellipsize unit names and truncate unit descriptions in the output of list-units and list-jobs.

Here is the whole script:

systemctl list-units -t service --full| cut -d' ' -f1| grep mypattern | while read s; do systemctl status $s; done
guettli
  • 3,591
  • 17
  • 72
  • 123
  • I aliased that long ago... `alias systemctl='systemctl -l'` – Michael Hampton Nov 05 '15 at 18:48
  • @MichaelHampton a recursive alias. I was not aware that this works. Great :-) – guettli Nov 07 '15 at 06:40
  • 1
    Note that it might be important to also include a lot of other flags like `--no-legend` and `--plain` if you intend to use it in scripts. See [this question](https://serverfault.com/q/942128/549727). Also, ALWAYS test for your SPECIFIC version of systemd - some flags (in particular, `--quiet`) may not behave the same across different versions. – cyqsimon Aug 18 '22 at 14:36