As a Linux user, knowing what services are running in your background is vital in managing system resources and understanding how to optimize and make the most of your system. Linux has numerous services running in the background, from system services such as cron to network services such as remote login.
A Linux service is a process or a group of daemons running in the background, and they can be managed in different ways. The commonly used process manager is systemd, and you require the systemctl command to manage the systemd service, especially to list all the services and other tasks such as starting, stopping, and enabling them. This post digs into how to list Linux services with systemctl.
Different Ways to List Services with Systemctl
Linux has the systemd to support managing all the services running in its background. There are different ways you can list Linux services using systemctl, and we will give various examples. That way, you will understand what command to run and at what point.
Example 1: Listing All Linux Services
When you don’t have a given criteria for the services you wish to list, you can opt to list them all. This option doesn’t categorize the services; you must scroll through them to check their state. Run the below command.
You will get an output listing all the Linux services and their information.
Before moving on to other examples, let’s quickly understand the different terms you will see in the output after listing the services.
- UNIT – It represents the name of the Linux services
- LOAD – It shows whether the given services are loaded. Note that you can have a loaded, yet inactive Linux service.
- ACTIVE – It symbolizes the state of the services, such as active or inactive. If a service shows that it is active, it is running in the background, and we will see how to get its details later in the article.
- SUB – The section gives more details about the state of a service.
- DESCRIPTION – It gives a brief introduction of what the service is all about.
Example 2: Listing Loaded Linux Services
You can quickly view all the loaded Linux services, irrespective of whether they are active, running, or failed, with the following command.
Example 3: List All Running Services
While it’s possible to check the status of a service to see if it’s running, a more realistic way to check all the running services is by filtering their state. This way, you will get a list of only the running services. Use the below command.
In the SUB section, you will notice that only the running services are listed, unlike when we listed the loaded services. Again, if a service is running, it implies that it is active and loaded.
Example 4: List All Enabled Services
Another way to use systemctl is to list the enabled Linux services on your system. The command to list the enabled or disabled services slightly changes.
Execute it as follows.
Enabled services are those configured at system boot. Notice how we’ve narrowed the output we get in this case only to show the state and vendor_preset. Our focus is on the state of the services.
Suppose you are targeting a specific service to see if it’s enabled. Use the grep command to filter the results. Check the example below.
Example 5: List All Disabled Services
Similar to listing the enabled services, we can modify the command to list the disabled services. For that, run the below command.
The disabled services are not configured to start automatically, and you must start them or enable them using systemctl. Read on to see how we can enable a disabled service in a later section.
Example 6: Extracting Service Information
With systemctl, you can check the information about a given service. Maybe you want to check its state to see if it’s running. Use the status option with systemctl and specify the target service.
Here’s an example where we are checking the status of cron.service.
Based on the output, we can see that it is active (running). Moreover, we can get other details related to the service from the output, such as memory usage, etc.
Example 7: Managing a Linux Service
The systemctl command lets you manage the state of a Linux service. You can change its state, such as starting or stopping it. For instance, the previous example confirmed that cron.service is running. If we wanted to stop this service, we would run the below commands.
We can then recheck its status to confirm that it’s no longer active.
To reinstate its previous state, use the systemctl start command as demonstrated below.
Similarly, if you have a disabled service like the one below, we can enable it.
Run the below command.
Verify its status to confirm that it is now an enabled Linux service.
That’s how you work with systemctl to list Linus services.
Conclusion
Systemd is responsible for managing Linux services, and it uses the systemctl utility to run the required commands, such as listing the services or changing their state. This post covers what systemctl is and gives examples of how to list Linux services, including filtering the services based on their state. Moreover, we’ve seen how you can check the status of a service and change its state. Try it out!