How to List Services in Linux Using Systemctl

Last updated: September 9, 2022 | Subhash Chandra

Service is a Linux program that runs continuously in the background. Some of the common examples of Linux services are reverse proxy servers, network, cron, SSH, and the high-performance web server. Linux supports multiple tools and methods to list and manage services. Some services start at the boot time and some services can be started after your system boots up. You can control Linux services with systemctl commands.

In this tutorial, we will learn how to list services in Linux using systemctl.

Using Systemctl Command

The systemctl command-line utility is used for controlling the services on Linux systems. Systemctl is part of the systemd software suite that can list all, enabled, active, stopped, or disabled services. All enabled services start at boot. Systemctl is the primary command for managing system services.

In the following examples, we will show you how to use the systemctl command to list services.

1. List All the Available Services

Systemctl provides a wide range of information about all the available services on your Linux systems. To list all available services, use the --all option.

Use the following command to list all active, inactive, failed, running, and stopped services:

systemctl --type service --all
systemctl list all available service

Let us describe each column to better understand the output:

  • UNIT – Every resource that systemd manages is denoted as a UNIT. It is the name of the service.
  • LOAD – Denotes if the specific service was loaded into memory or not after the system boot up.
  • ACTIVE – Denotes if the service is currently active or inactive.
  • SUB – Denotes the current state of the Linux service units.
  • DESCRIPTION – Provides a brief description of each service.

All these columns are available in the systemctl output, whether you display all available services or only the active/loaded units.

2. List Only Loaded and Active Services

To list only the active or loaded services, do not use the --all option. The following command output includes both running and stopped units, which are still active and loaded.

systemctl --type service
systemctl list only loaded and active servi

In this output, we see only the loaded and active services, which is also displayed under the LOAD and ACTIVE columns.

3. List Only the Running Services

Only the loaded and active services can be running, but it does not include all the available services. To list only the units that are running, use the --state option with the value running. For example:

systemctl --type service --state running
systemctl list only the running services

The --state filter can be used to sort out the services based on your requirements.

4. List All Stopped Services

Like listing all other services, you can also use systemctl status command to list all the stopped services. Use the --state option with the value exited and you will get a list of the services that were either stopped naturally or were stopped manually:

systemctl --type service --all --state exited
systemctl list all stopped services

Other Methods to Display Services in Linux

Linux distributions support other options to list services, along with the systemctl. The service command is one such option.

On my Ubuntu 22.04, I am able to use the service command to list services.

List All Available Services using service command

Use the following command to list all services on your Linux system, including active, inactive, running, or stopped services:

sudo service --status-all
using service command list all available services

The [ + ] and [ - ] symbols before each service name denotes the service status. The [ + ] symbol denotes that the service is running whereas [ - ] denotes that the service is stopped.

When you run this command for that first time, it may take some time for the output to display on the terminal. The service command collects data from the /etc/init.d/ directory.

Display Only Running Services using service command

You can also use the service command to run only the running services. Use the [ + ] symbol with the grep command to sort list only the services that are currently running:

service --status-all | grep '\[ + \]'
using service command only list running services

Extract Only Stopped Services using Service Command

Similar to listing Linux services, which are running, using the service command, you can also use the service command to list all stopped services using the [ - ] symbol with the grep command:

service --status-all | grep '\[ - \]'
using service command list only stopped service

Listing /etc/init.d

The service command retrieves service names and status from the /etc/init.d directory. Thus, you can directly list the units from /etc/init.d using the ls command. This method bypasses the source code execution that is required when you run the service command:

ls /etc/init.d
Listing /etc/init.d scripts

The ls command in this example merely lists the contents of the /etc/init.d directory. However, it does not provide you the status of the services. It just gets a list of all the services even if they are stopped or inactive.

Conclusion

Now almost all Linux distributions have adopted using systemd as its init system. Prefer using systemctl because it gives greater control options. Whereas service command is wrapper script and previously used for /etc/init.d scripts.

On my Ubuntu system, I am successfully able to use both systemctl and service command to list services. Over various versions of Ubuntu, users can reliably use service command to list, status check, start/stop services.

Thanks for reading, please leave your feedback and suggestion in the below comment section.

SHARE

Comments

Please add comments below to provide the author your ideas, appreciation and feedback.

Leave a Reply

Leave a Comment