Monday, November 4, 2024
HomeTutorialsHow to List Linux Services With systemctl?

How to List Linux Services With systemctl?

systemctl is a powerful service management tool under systemd for Linux distributions. By services, we mean a resource or unit, such as a software application that runs in the background without your intervention. These are also called daemons.

In this tutorial, we’ll learn how you can see any service, whether active, enabled, or loaded, using the systemctl command.

For demonstration purposes, we’ll be using Ubuntu 22.04. However, this will work on almost any modern Linux distribution.

Let’s get started!

Check If You’re Using systemd


The first thing you should do is check whether you’re using the systemd system manager or not. So, if you use a different Linux distribution in the future, you can know what system manager is being used before you use the systemctl command.

To see which system and service management system you’re using, use this command:

pstree | head -n 5
confirm system manager
Confirm your system manager

The pstree command displays all the system processes in a tree-like format. Since we’re only interested in seeing the system manager, we’re limiting it to only the first five lines here. As you can see, we have a systemd.

List All Services Using systemctl


The simplest way to list all services, no matter in what condition, is to run the below command:

systemctl list-units --type=service --all
list all services using systemctl
List all services using systemctl

As you can notice from the above screenshot, every single service on your system is being shown here. There are different categories, such as loaded, active, running, exited, etc. Adding the all flag to the command allows you to view every service on your system. This is convenient if you need to go through all existing services at once.

When you’re finished seeing the list, press the Q button to exit from that window.

However, sometimes, finding services of a particular category from this list will be time-consuming and cumbersome. You can also list services that meet a single or multiple criteria. For example, you can list only the enabled services. We’ll show you how to do that right now.

List Loaded Services Using systemctl


Loaded services are loaded into memory and running. These services may be loaded by a user manually or automatically during boot if configured that way.

To list only the loaded services, run this command:

systemctl list-units --type=service
list loaded services with systemctl
List loaded services with systemctl

You can also list services based on their current state. Let’s see how you can do that.

List Running Services Using systemctl


If you only want to see which services are currently running, then use this command:

systemctl list-units --type=service --state=running
list running services using systemctl
List running services using systemctl

These services are all loaded and running, as you can see under the LOAD and SUB columns.

List Enabled Services Using systemctl


Enabled services are configured so that they start functioning immediately after you boot up your system. You don’t need to start them whenever you start your device manually. To see the list of enabled services, run the following command:

systemctl list-unit-files --state=enabled
list enabled services using systemctl
List enabled services using systemctl

These services are all in the enabled state.

List Disabled Services Using systemctl


Similar to enabled services, you can view the list of disabled services, too. These services require the user to start themselves each time. To view these services, use this command:

systemctl list-unit-files --state=disabled
list disabled services using systemctl
List disabled services using systemctl

You can notice that all the services listed are disabled, as seen in the STATE column.

List Services with Other Sub-states


In the same way, you can view services that have a different state than the ones we’ve mentioned. For example, to list failed services, run this command:

systemctl --type=service --state=failed
list failed services using systemctl
List failed services using systemctl

Since there are no failed services in our case, the list is empty.

To check services with an exited state, use the below command:

systemctl --type=service --state=exited
list exited services using systemctl
List exited services using systemctl

These are services that were started, finished their execution, and are no longer running.

Let’s look at another example: masked services. Masked services are forcefully prevented from being started. To list masked services, run the below command:

systemctl list-unit-files --type=service --state=masked
list masked services using systemctl
List masked services using systemctl

This command also states the total number of masked unit files, which is 10 in our case.

List Services of Multiple Sub-states


What if you want to see services that are both failed and exited? Or perhaps any other combination of sub-states? You can do that by specifying all the states separated by a comma. See the below example code:

systemctl --type=service --state=failed,exited
list services of multiple states using systemctl
List services of multiple states using systemctl

In this method, you can view services having different combinations of states.

List Only One Service at a Time


So far, you’ve seen how to display a whole list of services that meet certain criteria. However, you can also display only one service and look at its details. To do so, push the service name as the parameter. Follow the format of this command:

systemctl status openvpn.service
list a single service using systemctl
List a single service using systemctl

As you may notice from the above screenshot, this method allows you to see a short description of a single service. You can see if the service is loaded or not, including the file path, its active status, PID, etc.

Check if a Service is Active or Enabled


If you want to know if a particular service is active or enabled without showing all the details, you can do that, too.

To see if a service is active or enabled, you need to input that service name after a special command like this:

systemctl is-active <service>
systemctl is-enabled <service>

So, let’s see some examples to understand the commands further.

systemctl is-active openvpn.service
systemctl is-enabled openvpn.service
Show if service if active or enabled
Show if a service is active or enabled

From our example, the particular service we chose is active and enabled, as seen in the above picture.

Final Thoughts


This tutorial shows you different ways to list services and daemons of your Linux system using the systemctl command. With this new knowledge, you can better manage Linux services and your system resources. You can also troubleshoot issues or optimize system performance with systemctl.

Mehedi Hasan
Mehedi Hasan
Mehedi Hasan is a passionate enthusiast for technology. He admires all things tech and loves to help others understand the fundamentals of Linux, servers, networking, and computer security in an understandable way without overwhelming beginners. His articles are carefully crafted with this goal in mind - making complex topics more accessible.

You May Like It!

Trending Now