- How to list services in Linux using the command-line
- BitLaunch
- BitLaunch
- How to list services in Linux
- Listing services with systemctl
- Types of Virtual Machines & Virtualization Technology
- How to install Yarn, the node.js package manager
- how to list all running services in linux from command line
- Systemd or SysV Init/OpenRC
- How to List all Services
- Gentoo
- CentOS / Red Hat Linux / Ubuntu and Related Variations
- Fedora
- How to List All Running Services Under Systemd in Linux
- Listing Running Services Under SystemD in Linux
How to list services in Linux using the command-line
Listing services in Linux is a key part of server management. Here’s how to do so on Ubuntu, Debian, CentOS, and Fedora.
BitLaunch
BitLaunch
Performing basic functions in the command-line can be challenging if you’re used to the GUI-based workflow of Windows or Linux desktops. A particular hurdle is working out how to get a list of running services when you cannot lean on hotkeys such as Ctrl + Shift + Esc or Ctrl + Alt + Del.
Listing services in Linux is a key part of server management. It allows you to check whether necessary services are running correctly or whether something is running that shouldn’t. Fortunately, there are several ways to list services in Linux, though the commands can vary depending on the distribution. In this blog, we’ll cover listing services on the most popular ones: Ubuntu, Debian, CentOS, and Fedora.
How to list services in Linux
Linux has multiple easy ways to list services, with the most obvious being the service command. This command should work on all distros that support System V init scripts.
This will list all services, whether they’re running or not, with a + next to the ones that are. You can also filter out services that are running using grep :
And the ones that aren’t by changing that + to a — :
You can find the status of a particular service by typing service status . For example, service ssh status will return:
ssh.service - OpenBSD Secure Shell server Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2022-12-19 08:21:39 UTC; 24h ago
Listing services with systemctl
Many will prefer to use the systemctl command over service because it shows more information and outputs in a tabular format. It also works on all of the Linux distributions mentioned. The list-units option will list all services, regardless of whether they are active or not.
systemctl list-units --type=service
systemctl list-units —type=service —all , meanwhile, shows services that are active or have failed.
You can filter those to only active service by using:
systemctl list-units -a --state=active
systemctl list-units -a --state=inactive
Want to list only running services? Use this instead:
systemctl list-units --type=service --state=running
If you want to see the services that have failed (for troubleshooting purposes), you can use the —state option:
systemctl list-units --state=failed
Types of Virtual Machines & Virtualization Technology
The different types of virtual machines fall into two categories: process virtual machines and virtual system machines. Here’s how they differ, and where KVMs come into the picture.
How to install Yarn, the node.js package manager
Yarn’s release marked a major step forward for package management in node.js, delivering features we now take for granted such as deterministic sub-dependency resolution and an offline cache. While
This post and this website contains affiliate links. See my disclosure about affiliate links.
how to list all running services in linux from command line
In operating system talk, a service is an application that can be run in the background, usually in perpetuity in order to perform some task or waiting for service requests from other applications to perform tasks. All operating systems, including Linux has some kind of support for these type of applications. Services are also sometimes referred to as daemons.
There are different services that are required for the functioning of an operating system, while others are used by the user. Some common examples of user services are web servers such as Apache or Nginx and database servers such as Oracle or MySql. Some examples of OS specific services are dbus, xdm, network etc.
Most Linux systems have a similar implementation when it comes to running services, but there are still some differences between distros. Many distros also comes with some easy to use GUI applications that allow you to view and manage system services, but not all. We will look at how this can be done from the command prompt.
I should confess that I have exclusively used and worked on Gentoo and have not been keeping up much with the other distros. So, it is quite possible that this post will skew more towards Gentoo but i will try to keep it as generic as possible.
This post solely deals with how to list all services that you are installed or are running on your system. It does not deal with how add, delete or manage the services. I will probably write another post to deal with those functions. I will however describe how to find the status of the service as well, as that somehow corresponds to the reason you might be listing them in the first place.
Systemd or SysV Init/OpenRC
Despite some difference with the commands used to manage the service, most Linux systems have one thing in common. It stores the service related files in the /etc/ folder. The startup scripts for the services are usually in the /etc/init.d/ folder. You might also want to check the /etc/rc.d folder if you do not find the init.d/ folder.
As your system starts up, there needs to be a program or application that finds and launches appropriate drivers and start services. The old and tried system has been SysV init which mainly loaded and ran the startup scripts from /etc/init.d folder. Systemd is a modern day replacement for init and is being adopted by many distros.
It is important that you be aware of what boot system you have, which will help you with finding the startup scripts. A detailed discussion on that topic is probably not for this post.
How to List all Services
As mentioned earlier, most systems keep the startup scripts for the services in the /etc/init.d/ folder. So, a simple listing of the directory contents should show you the list of services that are installed and available to you.
the file names in the folder usually match the name of the service.
One of the most widely used commands to list services and its status is the service command. It could actually be a symlink to the openrc command in some distros, such as Gentoo. So, this could differ between Linux distros, which means you will need to use a command that is specific to your distro or install another utility for it.
Gentoo
In Gentoo, the rc-status command can be used to list the running services. The rc-status command has several useful command line options.
–all or -a: This will list all the running or stopped services from all run levels, organized by run level.
–servicelist or -s: This option will list all available services, in a long list
–unused or -u: This will print out the list of services that has not been assigned a run level.
You can use the complementary commands: rc-update, rc-config and rc-service to manage the services in the system.
CentOS / Red Hat Linux / Ubuntu and Related Variations
The Ubuntu distribution and the various other related distros such as Kubuntu, Mint, Xubuntu etc uses Upstart by default instead of the traditional init system, and you can use the service command to list the services. Upstart is a event based system, so the output might vary depending on the state of the system and fired events.
You can also check the status of a single service, if you know the service name as shown below.
bash$ service mysql status
where mysql is the name of the service.
You can also use the initctl command, which is equivalent to the service command.
Fedora
Fedora does have support for the service utility that was described above, but they recommend the systemctl utility to manage services. The following command will list all the services that running in the system.
bash$ systemctl list-units —type=service
You can check the status of a single service with the same command and different command line arguments.
bash$ systemctl status httpd.service
where httpd.service is the name of the service.
If you have a different distribution that the ones mentioned and the above commands do not work for you then refer to the documentation that is specific to the distro. Also, be sure to execute the above commands with the superuser permissions by using sudo or equivalent.
Ideally, you should disable the services that are not required or being used. You should remove them from the run level as well. It is usually a waste of hardware resources if it running all the time even if it has a small footprint. There is also a possibility of it being a security risk, especially if it has an open port and is listening on it.
How to List All Running Services Under Systemd in Linux
Linux systems provide a variety of system services (such as process management, login, syslog, cron, etc.) and network services (such as remote login, e-mail, printers, web hosting, data storage, file transfer, domain name resolution (using DNS), dynamic IP address assignment (using DHCP), and much more).
Technically, a service is a process or group of processes (commonly known as daemons) running continuously in the background, waiting for requests to come in (especially from clients).
Linux supports different ways to manage (start, stop, restart, enable auto-start at system boot, etc.) services, typically through a process or service manager. Most if not all modern Linux distributions now use the same process manager: systemd.
Systemd is a system and service manager for Linux; a drop-in replacement for the init process, which is compatible with SysV and LSB init scripts, and the systemctl command is the primary tool to manage systemd.
In this guide, we will demonstrate how to list all running services under systemd in Linux.
Listing Running Services Under SystemD in Linux
When you run the systemctl command without any arguments, it will display a list of all loaded systemd units (read the systemd documentation for more information about systemd units) including services, showing their status (whether active or not).
To list all loaded services on your system (whether active; running, exited, or failed, use the list-units subcommand and —type switch with a value of service.
# systemctl list-units --type=service OR # systemctl --type=service
And to list all loaded but active services, both running and those that have exited, you can add the —state option with a value of active, as follows.
# systemctl list-units --type=service --state=active OR # systemctl --type=service --state=active
But to get a quick glance at all running services (i.e. all loaded and actively running services), run the following command.
# systemctl list-units --type=service --state=running OR # systemctl --type=service --state=running
If you frequently use the previous command, you can create an alias command in your ~/.bashrc file as shown, to easily invoke it.
Then add the following line under the list of aliases as shown in the screenshot.
alias running_services='systemctl list-units --type=service --state=running'
Save the changes in the file and close it. And from now onwards, use the “running_services” command to view a list of all loaded, actively running services on your server.
# running_services #use the Tab completion
Besides, an important aspect of services is the port they use. To determine the port a daemon process is listening on, you can use the netstat or ss command as shown.
Where the flag -l means print all listening sockets, -t displays all TCP connections, -u shows all UDP connections, -n means print numeric port numbers (instead of application names) and -p means show the application name.
# netstat -ltup | grep zabbix_agentd OR # ss -ltup | grep zabbix_agentd
The fifth column shows the socket: Local Address:Port. In this case, the process zabbix_agentd is listening on port 10050.
Also, if your server has a firewall service running, which controls how to block or allow traffic to or from selected services or ports, you can list services or ports that have been opened in the firewall, using the firewall-cmd or ufw command (depending on the Linux distributions you are using) as shown.
# firewall-cmd --list-services [FirewallD] # firewall-cmd --list-ports $ sudo ufw status [UFW Firewall]
That’s all for now! In this guide, we demonstrated how to view running services under systemd in Linux. We also covered how to check the port service is listening on and how to view services or ports opened in the system firewall.
Do you have any additions to make or questions? If yes, reach us using the comment form below.