How to use Systemctl to list all Linux services
When administering a Linux system, it is important to understand how to control and monitor system services. Systemd, the system and service manager for most Linux distributions, provides a powerful set of tools for this purpose. Today's article will dive into how you can list all the services running in systemd, focusing on the Ubuntu terminal as an example.
What is Systemd?
Systemd is an init system used to start user space and manage system processes after boot. It is now used by most major Linux distributions. It replaces the old SysVinit system and has become the standard for service management in Linux.
Check the status of services
To start, the main command to interact with systemd is systemctl. Let's see how we can use systemctl to list all running services.
List running services using systemctl
You can list all running systemd services with the following command:
systemctl list-units --type=service --state=running
When you run this command in Ubuntu terminal, it will display a list of all running services. The output might look like this:
UNIT LOAD ACTIVE SUB DESCRIPTION ● atd.service loaded active running Deferred execution scheduler avahi-daemon.service loaded active running Avahi mDNS/DNS-SD Stack cron.service loaded active running Regular background program processing daemon dbus.service loaded active running D-Bus System Message Bus networking.service loaded active running Raise network interfaces ssh.service loaded active running OpenBSD Secure Shell server
This output shows several columns:
- UNIT: Name of the service.
- LOAD: Indicates whether the service configuration file has been loaded successfully or not.
- ACTIVE: High level activation state.
- SUB: Low level activation state.
- DESCRIPTION: A brief description of the service.
The default output is quite useful, but sometimes a bit overwhelming. If you prefer a simpler view, you can customize the output with the --no-pager option to prevent output from being sent through the paging engine, and grep to filter through services. For example:
systemctl list-units --type=service --state=running --no-pager | grep ssh
This command will only show ssh related services, which is handy if you are specifically interested in the status of SSH related services .
How to handle services that are not running
It is also important to know how to find services that are not running. For example, to see which services have failed, you can use:
systemctl --failed
This command will list services that are not loading or not starting. Here is how the output might appear:
UNIT LOAD ACTIVE SUB DESCRIPTION ● nginx.service loaded failed failed A high performance web server ● mysql.service loaded failed failed MySQL Community Server
This is especially useful for troubleshooting as it highlights services that need attention.
Additional Tips and Tricks
Filter the list
Systemd provides several ways to filter and view specific types of services. For example, you can use the --all flag to list all services regardless of their state, or specify a specific service by its exact name for detailed state information:
systemctl status ssh.service
Enjoy control
If you like to tweak and have granular control over what is running on your system, you will appreciate the capabilities of systemd. The tools that systemd provides are powerful and flexible, allowing for the granular management of service state that is essential for any system administrator.
How to list all services, whether running or not?
You can list all installed services, whether running or not, using the following command:
systemctl list-units --type=service --all
This command displays every service installed on your system, including those that are not currently running.
How to start or stop a service?
To start a service, use:
sudo systemctl start [service-name].service
To stop a service, use:
sudo systemctl stop [service-name].service
Replace [service-name] with the name of the service you want to control.
How to enable a service to start on boot?
To ensure the service runs automatically on startup, use:
sudo systemctl enable [service-name].service
This command creates a symbolic link from the system's copy of the service file (usually located in /etc/systemd/system/ or /lib/systemd/system/ ) to the location where systemd looks for files that run automatically at boot.
Which command to check the status of a specific service?
To check the status of a specific service, you can use:
systemctl status [service-name].service
This command provides detailed information about the service, including current state, most recent logs, and configuration.
How to reload a service after changing its configuration?
After modifying the service's configuration, you can reload the service to apply these changes using:
sudo systemctl reload [service-name].service
This command tells the service to reload its configuration files without completely stopping and restarting the service.
Is there a way to view the logs of a specific service?
Yes, to view the logs for a specific service, you can use the journalctl command:
journalctl -u [service-name].service
This command will display log entries for the specified service. Adding -f will monitor the log, displaying new entries as they appear.
Can you list services by their load state or running state?
Absolutely! You can filter services based on their load state or running state using:
systemctl list-units --type=service --state=loaded
or
systemctl list-units --type=service --state=active
These commands help you narrow down the list to services that are loaded into the system or are currently running.
Mastering how to list and manage services with systemd is an important skill for anyone using Linux. We've explored how to check the status of services, how to start, stop, and manage them, and how to ensure they're working as expected using commands like systemctl. Whether you're troubleshooting, tweaking your system, or just curious about what's running under the hood, the tools provided by systemd provide a comprehensive and powerful way to keep your Linux system organized and running efficiently.
You should read it
- How to manage Linux services using Systemd
- Disabling unnecessary services for faster boot Linux
- Google blacklisted some web browsers on Linux, blocking access to Google services
- Microsoft officially submitted an application to join 'Linux secretion'.
- List device names, drive information, and partitions in Linux with lsblk
- How is Arch Linux different from other Linux versions?
- 14 interesting Linux commands in Terminal
- 18 Interesting Linux Commands in Terminal
May be interested
- How to set and list environment variables in Linuxif you want to do something that requires using the command line, you will still need to know about environment variables. this may seem like a complicated term, but actually environment variables are easy to understand.
- How to manage remote Linux server using SSHmanaging the server is still a necessary and sometimes heavy task. fortunately, secure shell (ssh) is available - a network protocol that allows services to run on an unsecured network.
- How to list all physical Ethernet ports on Linux serverunlike conventional servers, rack servers must be resilient and often contain several physical ethernet ports or nics (network interface cards) to be able to connect to multiple networks at the same time.
- 11 uses of ps command in Linuxfor system administrators, ps is a frequently used tool. the ps command is used to list the processes currently running on the system, with many available filtering and display modes via flags and arguments.
- How is Arch Linux different from other Linux versions?arch linux is arguably the most misunderstood linux distribution. many people find arch difficult to install and maintain.
- How to view your favorite streaming service on Linuxthere are many streaming services and most people have their own favorite service. unfortunately, many online streaming services do not support linux or even actively block this operating system.
- How to check the registered Vinaphone service?in the tendency of network operators to promote content provision with a multitude of different value-added services (vat), a subscriber needs to control the list of services he / she has registered to avoid the situation except for wasted money ... don't understand why. like viettel, 2 most convenient ways for a vinaphone subscriber to view the registered list of services are sms or check on the official vinaphone website. also if you want to try you can use ussd protocol with code * 123 # ...
- Signal and Trap in Unix / Linuxsignals are software interrupt signals that are sent to a program that indicates a serious event has occurred. these events can be very diverse from user requests to illegal memory access. some signals, like signal interrupts, indicate that a user has asked the program to do something without being in control.
- 14 interesting Linux commands in Terminalterminal is a very powerful tool, but it can become 'interesting' through a few bash commands that quantrimang will introduce to you later. let's follow up and find out because some commands are quite useful.
- How to set up your own Git server on Linuxwhile you can count on globally renowned git hosting services like github, in some cases it is better to host a personal git server for enhanced privacy, customizability, and security.