You need to know what services are running on your system. And today, we’ll talk about how you can list all services in Ubuntu. Services are the background applications that are available for the proper functioning of a Linux system. Whenever the system requires a specific service, it enables it. In Ubuntu, systemd
is responsible for the handling of the system and its services.
In this article, we will look at various methods of listing services available in our system.
Using the service command
As the name suggests, the service command lists the services as well as their status on the terminal. We run the command:
service --status-all

Running the command for the first time may take a while since it collects the services from '/etc/init.d/'
directory. The symbols before the name of each service denote the status of the service. '[ + ]'
represents a running service whereas '[ - ]'
means a stopped service.
1. Display only running services
It is fairly simple to extract only the running services from the service
command, provided the user has the knowledge of grep
command. It is done by:
service --status-all | grep '\[ + \]'

The grep command is a Linux tool for capturing certain patterns or words from text. The pipe '|'
symbol denotes the transfer of output of one command to the input of the following command.
2. Extract only stopped services
Similarly, the above method can be used to list all the stopped services by:
service --status-all | grep '\[ - \]'

Listing services directly from /etc/init.d
After knowing the fact that, service
command extracts services from /etc/init.d
directory, we can list the contents of the directory to bypass the source code run every time for the service
command.
ls /etc/init.d

The ls command is used to list the contents of any directory in Linux. The green color for each filename denotes an executable file.
The only drawback using this method to list all services in Ubuntu is that we can not figure out the status of each service.
Using the systemctl command
systemctl
stands from systemd control, that is, this command is responsible for actions of systemd
. In order to list all the available services, we run:
systemctl --type service --all

systemctl
provides a ton of information as compared to the service
command, the reason being that systemctl
is a primary command for the manager of system’s services, systemd
.
Let us understand each column in the output:
- UNIT –
systemd
regards every resource it manages as a unit. Here, UNIT denotes a service name.\ - LOAD – Whether the service was loaded into the memory after boot up.
- ACTIVE – Whether the service is currently active or inactive.
- SUB – The current state of the service.
- DESCRIPTION – A short description of the particular service.
There can be few filters applied to the above command to fetch certain results.
1. List only the loaded and active services
In order to list only the loaded and active services, we will omit the -all
option.
systemctl --type service

The output columns remain same as before. Whenever we run the systemctl
command, a short statistic is also presented at the end of the output.

In the figure we can find out the number of loaded units/services in our system.
2. List only running services
To list only the running services, we run:
systemctl --type service --state running

It is quite obvious that only the loaded and active services, would be running. Therefore, we can omit the --all
option from the command. To find out the number of running services, we can scroll to the bottom of the output.
3. List only the stopped services
We can list the stopped/exited services by:
systemctl --type service --all --state exited

Similarly using the active
, inactive
or loaded
states, we can filter the list of services as per our need.
Conclusion
The easiest way of listing services is using the service
command, but it lacks information about the service, where systemctl
is more useful. The use of any command depends on the context of the user’s needs.
We hope this article provided enough information related to the listing of services in Ubuntu or other Linux distributions. Feel free to comment below if we missed any method.