1. Introduction

Running the systemctl command alone shows us a list of loaded units. But what if we want to see a list of just one unit type or units in a certain state?

This tutorial discusses how to list all enabled services using systemctl (the systemd control system and service manager). We talk about the list-unit-files subcommand and a few other handy systemctl subcommands and options.

2. Listing Enabled Services

The systemctl command comes with seven groups of subcommands, one of which is the Unit File Commands. list-unit-files is one of systemctl‘s Unit File Commands*.* As its name says, it lists all the unit files installed on the system.

So, what are unit files? A unit file is basically an ini file containing the configuration of a service, snapshot, timer, slice, scope, socket, or any other unit monitored and managed by systemd.

2.1. Listing Unit Files

As mentioned earlier, running systemctl alone displays loaded units:

$ systemctl
  UNIT                                                                                                  LOAD   ACTIVE SUB       DESCRIPTION
  proc-sys-fs-binfmt_misc.automount                                                                     loaded active waiting   Arbitrary Executable File Forma>
  sys-devices-pci0000:00-0000:00:01.1-ata3-host2-target2:0:0-2:0:0:0-block-sr0.device                   loaded active plugged   VBOX_CD-ROM VBox_GAs_7.0.6
  sys-devices-pci0000:00-0000:00:03.0-net-enp0s3.device                                                 loaded active plugged   82540EM Gigabit Ethernet Contro>
...truncated...
● apache2.service                                                                                       loaded failed failed    The Apache HTTP Server
...truncated...
  phpsessionclean.timer                                                                                 loaded active waiting   Clean PHP session files every 3>
  systemd-tmpfiles-clean.timer                                                                          loaded active waiting   Daily Cleanup of Temporary Dire>

...truncated...
lines 97-132/132 (END)

But when we add the list-unit-files subcommand, we get a list of all the unit files (not units) in all the possible unit file states:

$ systemctl list-unit-files
UNIT FILE                                                                     STATE           VENDOR PRESET
proc-sys-fs-binfmt_misc.automount                                             static          -
-.mount                                                                       generated       -
dev-hugepages.mount                                                           static          -
...truncated...
docker-1adcb3e4a2b014b08de2adea0e0bcc65c7faf535034679393e2c3e90c1763d7c.scope transient       -
session-1.scope                                                               transient       -
anacron.service                                                               enabled         enabled
apache-htcacheclean.service                                                   disabled        enabled
...truncated...
cryptdisks.service                                                            masked          enabled
dbus-fi.w1.wpa_supplicant1.service                                            alias           -
...truncated...
systemd-fsck-root.service                                                     enabled-runtime enabled
...truncated...
250 unit files listed.
lines 224-253/253 (END)

2.2. Listing Unit Files by State or Type

Using the —state flag, we can get a list of all unit files in a particular state:

$ systemctl list-unit-files --state=disabled
UNIT FILE                              STATE    VENDOR PRESET
proc-sys-fs-binfmt_misc.mount          disabled disabled
apache-htcacheclean.service            disabled enabled
...truncated...
poweroff.target                        disabled disabled
reboot.target                          disabled enabled

27 unit files listed.

When we run list-unit-files with the —type flag, we can get a list of all unit files of a particular unit type:

$ systemctl list-unit-files --type=mount
UNIT FILE                     STATE     VENDOR PRESET
-.mount                       generated -
dev-hugepages.mount           static    -
dev-mqueue.mount              static    -
media-cdrom0.mount            generated -
proc-sys-fs-binfmt_misc.mount disabled  disabled
sys-fs-fuse-connections.mount static    -
sys-kernel-config.mount       static    -
sys-kernel-debug.mount        static    -
sys-kernel-tracing.mount      static    -

9 unit files listed.

2.3. Listing Enabled Service Unit Files

Finally, we can list all enabled services from systemctl when we combine the list-unit-files subcommand with —type=service and —state=enabled:

$ systemctl list-unit-files --type=service --state=enabled
UNIT FILE                   STATE   VENDOR PRESET
anacron.service             enabled enabled
apache2.service             enabled enabled
apparmor.service            enabled enabled
atd.service                 enabled enabled
bluetooth.service           enabled enabled
...truncated...
unattended-upgrades.service enabled enabled
vsftpd.service              enabled enabled
wpa_supplicant.service      enabled enabled

23 unit files listed.

2.4. Listing Disabled and Enabled Service Unit Files

By slightly modifying the previous command, we can also get a list of all enabled and disabled services:

$  systemctl list-unit-files --type=service --state=disabled,enabled
UNIT FILE                              STATE    VENDOR PRESET
anacron.service                        enabled  enabled
apache-htcacheclean.service            disabled enabled
[email protected]           disabled enabled
...truncated...
[email protected]          disabled enabled
wpa_supplicant.service                 enabled  enabled
[email protected]                disabled enabled

41 unit files listed.

We could try grepping the list-unit-files command with ‘enabled’ as our pattern:

$ systemctl list-unit-files --type=service | grep enabled
anacron.service                        enabled         enabled
apache-htcacheclean.service            disabled        enabled
[email protected]           disabled        enabled
...truncated...
[email protected]          disabled        enabled
wpa_supplicant.service                 enabled         enabled
[email protected]                disabled        enabled
x11-common.service                     masked          enabled

However, as we see above, this will include non-enabled services whose vendor presets are set to enabled. Of course, this isn’t ideal if we only want to see services that are actually enabled.

3. Listing Active Services

While list-unit-files displays a list of all unit files, list-units shows a list of units currently loaded in memory – the same thing we get when we run systemctl alone. Basically, when we run systemctl list-units, our output would be the same as when we ran systemctl.

Running the following command shows us a list of active units currently loaded on our system:

$ systemctl --state=active

The command below does the same thing as the one above:

$ systemctl list-units --state=active

Modifying any of those two commands by adding —type=service gives us a list of all active services currently loaded on the system:

$ systemctl --state=active --type=service
  UNIT                               LOAD   ACTIVE SUB     DESCRIPTION
  apparmor.service                   loaded active exited  Load AppArmor profiles
  atd.service                        loaded active running Deferred execution scheduler
...truncated...
  wpa_supplicant.service             loaded active running WPA supplicant

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.
40 loaded units listed.
lines 17-46/46 (END)

We can produce the same result with this command:

$  systemctl list-units --state=active --type=service

4. Conclusion

In this article, we discussed how to display a list of all enabled service unit files from systemctl. We also saw how to list all active, loaded services.

Trying to list all enabled systemd services by grepping the word ‘enabled’ to systemctl list-unit-files –type=service may display a list of enabled services. However, because it may also display services whose preset states are set to enabled but are currently not enabled, doing so isn’t optimal.