Home Learn Linux How to Use Systemctl to List All Services in Linux

How to Use Systemctl to List All Services in Linux

Learn how to use systemctl to list all services on your Linux system, including active, inactive, and failed services. This quick guide offers practical command line tips to help you manage and troubleshoot your system efficiently.

by John Horan
systemctl list services

When managing a Linux system, understanding how to control and monitor system services is crucial. Systemd, the system and service manager for most Linux distributions, offers a powerful suite of tools for this purpose. Here, we’ll delve into how you can list all running services under systemd, focusing on a Ubuntu terminal for our examples.

What is systemd?

Systemd is an init system used to bootstrap the user space and manage system processes after booting. It is now used by most major Linux distributions. It replaces the older SysVinit system and has become the standard for service management in Linux.

Checking the status of services

To begin with, the primary command to interact with systemd is systemctl. Let’s see how we can use systemctl to list all currently 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 your Ubuntu terminal, it displays a list of all active services. Here’s what the output might look like:

  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: The name of the service unit.
  • LOAD: Indicates whether the unit’s configuration file has been loaded successfully.
  • ACTIVE: The high-level activation state.
  • SUB: The low-level activation state.
  • DESCRIPTION: A brief description of the service.

Personally, I find the default output quite informative, but sometimes it’s a bit too much. If you prefer a simpler view, you can customize the output using the --no-pager option to prevent output from being sent through a pager, and grep to filter through services. For example:

systemctl list-units --type=service --state=running --no-pager | grep ssh

This command will only show services related to ssh, which is handy if you’re specifically interested in the status of SSH-related services.

How to handle non-running services

It’s also important to know how to find services that aren’t running. To see services that have failed, for example, you can use:

systemctl --failed

This will list units that have failed to load or to start. Here’s 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 particularly useful for troubleshooting issues, as it highlights which services need attention.

Additional tips and tricks

Filtering the list

Systemd offers several ways to filter and view specific types of services. For example, you can use the --all flag to list all units regardless of their state, or specify a particular unit by its exact name to get detailed status information:

systemctl status ssh.service

Enjoying the control

As someone who enjoys fine-tuning and having granular control over what’s running on my systems, I appreciate systemd’s capabilities. The tools systemd offers are powerful and flexible, allowing for detailed management of service states that are essential for any system administrator.

FAQ: Listing and managing services under systemd

What is systemd?

Systemd is the init system and service manager that has become the standard for initializing, managing, and tracking system services and sessions in modern Linux environments.

How do I list all services, whether active or not?

You can list all installed services, whether they are active or not, using the following command:

systemctl list-units --type=service --all

This command shows every service unit installed on your system, including those that are not currently running.

How can I 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 wish to control.

How do I enable a service to start at boot?

To ensure a service starts automatically at boot, use:

sudo systemctl enable [service-name].service

This command creates a symbolic link from the system’s copy of the service file (usually in /etc/systemd/system/ or /lib/systemd/system/) to the location where systemd looks for autostart files at boot time.

What is the 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 provides detailed information about the service, including its current state, last logs, and configuration.

How can I reload a service after changing its configuration?

After modifying a service’s configuration, you can reload the service to apply these changes with:

sudo systemctl reload [service-name].service

This command tells the service to reload its configuration files without stopping and restarting the service entirely.

Is there a way to see logs for a specific service?

Yes, to see logs for a specific service, you can use the journalctl command:

journalctl -u [service-name].service

This will display the log entries for the specified service. Adding -f will follow the log, showing new entries as they appear.

Can I list services by their load state or active state?

Absolutely! You can filter services based on their load or active states 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 currently active.

Conclusion

Mastering how to list and manage services with systemd is a crucial 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 operate as expected with commands like systemctl. Whether you’re troubleshooting, fine-tuning your system, or just curious about what’s running under the hood, the tools provided by systemd offer a comprehensive and powerful way to keep your Linux system organized and efficient.

You may also like

1 comment

Jalal Hajigholamali April 24, 2024 - 6:32 AM

Hi,
Thanks a lot
Very useful article

Reply

Leave a Comment

fl_logo_v3_footer

ENHANCE YOUR LINUX EXPERIENCE.



FOSS Linux is a leading resource for Linux enthusiasts and professionals alike. With a focus on providing the best Linux tutorials, open-source apps, news, and reviews written by team of expert authors. FOSS Linux is the go-to source for all things Linux.

Whether you’re a beginner or an experienced user, FOSS Linux has something for everyone.

Follow Us

Subscribe

©2016-2023 FOSS LINUX

A PART OF VIBRANT LEAF MEDIA COMPANY.

ALL RIGHTS RESERVED.

“Linux” is the registered trademark by Linus Torvalds in the U.S. and other countries.