591

How can I list all enabled services from systemctl?

I know running systemctl command by itself lists all services, but I would like to only get the enabled ones.

oceanBT
  • 6,137
  • what do you mean by enabled? You mean services that are running? – Gen Jul 05 '16 at 18:28
  • 14
    @Gen enabling a service is quite different from starting it. See man systemctl. – Jos Jul 05 '16 at 18:35
  • 6
    Fascinating. The lowest rated answer is the most "correct" answer, even though it is clearly not the best answer. This excellent question (and its answers) is an interesting example of how systemd violates the long-standing (and brilliant) design principles of Unix & Co. @FelipeAlvarez complains that the most-accepted answer assumes systemd follows the unix design philosopy, but systemd/systemctl can do exactly what he wants (most experienced users will just consider that complete bloat). I begin to see more clearly why Linus Torvalds is so vehemently critical of systemd. – BISI Dec 13 '18 at 18:20
  • If you want to list "templated" services (blabla@instance.service), do not forget to add "--all" - thanks to @rafdouglas below. – jehon Jul 06 '22 at 14:01
  • @BISI is the lowest rated answer today still the answer that was lowest rated when you wrote your comment - or, iow, which answer do you think is the correct one? – René Nyffenegger Mar 31 '24 at 15:53

10 Answers10

773

systemctl list-unit-files | grep enabled will list all enabled ones.

If you want which ones are currently running, you need systemctl | grep running.

Use the one you're looking for. Enabled, doesn't mean it's running. And running doesn't mean it's enabled. They are two different things.

Enabled means the system will run the service on the next boot. So if you enable a service, you still need to manually start it, or reboot and it will start.

Running means it's actually running right now, but if it's not enabled, it won't restart when you reboot.

Delorean
  • 10,923
  • 12
    annoying to have to use an external tool (grep) to show this vital information. But thank you for showing us the way :) – Felipe Alvarez Feb 15 '17 at 02:43
  • 1
    @FelipeAlvarez You're welcome! However, grep is not an external tool, it's a base command. You could always write your own scripts with simpler names that will run those commands for you. I do this often myself. – Delorean Feb 15 '17 at 20:36
  • 1
    Grep is not systemctl, so the OS has to make another call to another tool. That's what I meant :-) One tool (systemctl) should do one job, very, very well. – Felipe Alvarez Feb 15 '17 at 23:23
  • 58
    @FelipeAlvarez Correct. But that's how Linux works. Many small binaries that work well with each other. systemctl does what is asked, it lists services. There is no filtering command built-in to systemctl because grep already exists and can do that well with any program's output. It's how it's always been :) – Delorean Feb 16 '17 at 16:01
  • 8
    I agree and so it should be. But, systemd already tries to do SO much that I wonder why it can't list enabled services? – Felipe Alvarez Feb 18 '17 at 00:45
  • 3
    @FelipeAlvarez Linux is all about small tools, and it's part of Linux's philosophy which was inherited from Unix : "Make each program do one thing well. To do a new job, build afresh rather than complicate old programs by adding new "features"." - The Bell System Technical Journal from 1978 – Delorean Mar 20 '17 at 19:12
  • 7
    systemctl | grep running do not list anything to me! Even if something is running is only listed as for his status like: enabled, disabled, masked, static – Cirelli94 Apr 13 '17 at 10:34
  • +1 I was able to grep systemctl to see if mysql service was running using systemctl | grep -E 'running.*active|active.*running' | grep mys – Eric Hepperle - CodeSlayer2010 Apr 20 '17 at 16:01
  • @Cirelli94 That is odd. systemctl with no other options shows an output where the 4th column states if something is running/failed/exited etc. Are you sure you're running Ubuntu 16.04? – Delorean Apr 20 '17 at 18:16
  • 1
    @EricHepperle-CodeSlayer2010 You don't even need that much, you can just do systemctl | grep mysql to see if it's running. – Delorean Apr 20 '17 at 18:18
  • 49
    Simpler: systemctl list-unit-files --state=running – Will Sep 02 '17 at 10:40
  • 2
    It appears that systemctl list-unit-files does not list ALL serivces. For example, it does not list tinc, even though tinc is enabled. Maybe systemctl list-unit-files only lists services that have unit files? But fails to lists any services that might be enabled via legacy sysv style init scripts? – mpb Dec 17 '17 at 22:42
  • grepping the output of systemctl seems to produce a mess of lines broken in weird places... – Tom Feb 19 '18 at 15:03
  • 1
    @TomH No issues here on 16.04 or 17.10 or 18.04. Verify your installation. – Delorean Feb 21 '18 at 05:46
  • In general, the names of unit files do not have to be the same as the names of units. For example on 18.04 there is a unit file sshd.service, but the unit is actually called ssh.service. Same with service templates. – OrangeDog Jan 11 '19 at 18:28
  • This does not work for instances that take an argument, e.g. you may have my@x.service enabled and my@y.service disabled. All you will see from systemctl list-unit-files is my@.service indirect which is useless. – Walf Jul 23 '20 at 08:30
  • @Walf try to add --all to systemctl command . – digital_infinity Sep 14 '20 at 10:33
  • @digital_infinity that made no difference to instances. – Walf Sep 15 '20 at 02:18
  • @Walf I used --all with instances after I had made them them enabled to list status of all instances or start them all. Did use wildcards ? (systemctl list-unit-files 'my@*' --all) – digital_infinity Sep 16 '20 at 07:33
  • @Walf Now I can see --all works correctly with status but does not work with list-unit-files – digital_infinity Sep 16 '20 at 07:45
  • No systemd unit file must ever contain the string "running" or "enabled". long_running_backup.service or gpu_enabled_calculation.service will lead to bugs in the future. – Unix philosophy at its best. – ominug Nov 18 '22 at 08:58
  • To make it a bit more robust: add parameter --no-legend to systemctl and -w to grep. – ominug Nov 18 '22 at 09:13
191

man systemctl states:

--state=

The argument should be a comma-separated list of unit LOAD, SUB, or ACTIVE states. When listing units, show only those in the specified states. Use --state=failed to show only failed units.

Explanation:

LOAD: Reflects whether the unit definition was properly loaded.
ACTIVE: The high-level unit activation state, i.e. generalization of SUB.
SUB: The low-level unit activation state, values depend on unit type.

Though you can also use this to only show enabled units with:

systemctl list-unit-files --state=enabled

If a unit is enabled that means that the system will start it on startup. Though setting something to enabled doesn't actually also start it so you will need to do that manually, or reboot the system after setting it to enabled.

  • 11
    To enable and start at the same time: systemctl enable --now ... – Mmmh mmh Jul 29 '17 at 20:24
  • 2
    --state=enabled has no effect on systemd version 215 (on Raspbian 8 Jessie), but it does work on systemd version 229 (on Ubuntu 16.04.03 Xenial). – mpb Dec 17 '17 at 22:15
  • @mpb: But yet it works perfectly fine on version 235 on Arch Linux. –  Dec 17 '17 at 23:07
  • You can also check --state=generated for generated unit files that might be running (the pihole-FTL service works this way, for example). – mgalgs Aug 26 '21 at 17:24
  • The answer lacks of a --type service to filter only that type of units. 2. @mgalgs list-unit-files now includes generated units
  • – Pablo Bianchi Oct 29 '21 at 07:18
  • You don't have the service(s) if they are based on a template servicename@.service while --list-units does – Mat M Mar 15 '23 at 12:51