How to list services on Linux?

A service in Linux is a program running in the background some of these are essential for the operating system. These services lack an interface so users cannot interact with them but using a few Linux commands a user can manage them.

The services on a Linux or Unix system are also referred to as daemons. Usually, the name of a daemon ends with the letter d. For example, httpd is the service or daemon name that handles apache similarly sshd handles SSH.

In this article, we will discuss different ways to list services on a Linux system.

List all services in Linux using the systemctl command

Most of the modern Linux distributions today use systemd as init system. On these systems, we can use the systemctl command to manage services.

To list all the services use –

sudo systemctl list-unit-files --type service --all

You will see the given output.

You can see all the services listed here by scrolling the output. In the STATE column, you can see the defined state of these services.

enabled – These are services that are currently running.

disabled – These are inactive services and can be started using a command.

masked – The masked services wouldn’t run unless that property removed from them.

static -These will only be used when other services need them.

generated – These services are generated through a SysV or LSB init script with a systemd generator.

You can use the given command to find services matching with a specific pattern.

sudo systemctl list-unit-files | grep 'apache'

This will display all the lines matching apache.

Here the second column shows the state of the services and the third column is vendor_preset.

To display all active services on a system, use –

systemctl | more

You can scroll the list of all active services by pressing enter.

Managing services using systemctl

There are a few commands that can be used to manage services on a system.

You can check the status of a service by using –

sudo systemctl status service_name

You can start a disabled service by using –

sudo systemctl start service_name

Similarly, you can disable an active service by using –

sudo systemctl stop service_name

To know more options that can be used with the systemctl command to manage a service see its man page.

man systemctl

Display list of all services on older Linux systems

Sysvinit is a traditional init system for Unix/Linux whose primary purpose is initializing, managing, and tracking system services and daemons. The older version of many Linux distributions uses sysvinit. We can use the service command to manage services on these systems.

You can check the list of all services by the given command.

chkconfig --list

Managing services using the service command

To check the status of service, use –

sudo service service_name status

If you want to start service then use –

sudo service_name start

You can disable an active service by using –

sudo service_name stop

Using netstat command to list service in Linux

Another way to display the list of services on a Linux system is to use the netstat command.

Netstat is a command-line utility that displays network connections, routing tables, and a number of network interface and protocol statistics.

It comes pre-installed on many Linux systems. But if it is not on your system then use the given command to install it.

This command is part of the net-tools package. To install it on Ubuntu/Debian/ Linux Mint etc use –

sudo apt install net-tools -y

OR if you are using CentOS /RHEL then use –

sudo yum install -y net-tools

Now to check all the services running on a system, use –

netstat -a

You can see the output of this command in the given image.

Conclusion

We have explained various ways to display the list of services on a Linux system. Now if you have a query or feedback then write us in the comments below.

Leave a Comment