sodcalculator

10 Tech How-To

List Linux Services with systemctl: Step-by-Step

Guide 10-44502 · Updated · Step by step

This guide shows you how to list Linux services using the systemctl command, which is the standard tool for managing services on systems running systemd (most modern distros like Ubuntu, Debian, Fedora, CentOS, and Arch). You’ll learn to view all services, filter by state (running, stopped, failed), and get useful details like whether a service starts at boot. No special permissions are needed just to list services, but you’ll need sudo for some variations.

What You’ll Need

  • A Linux system with systemd (check with ps -p 1 – if it shows systemd, you’re good).
  • Access to a terminal (Ctrl+Alt+T on most desktops).
  • Basic familiarity with the command line.
  • For some commands (like listing failed services with full details), you may need sudo privileges.

Step-by-Step

  1. Open a terminal. On most Linux desktop environments, you can press Ctrl+Alt+T or search for “Terminal” in the applications menu.
  2. List all services (default view). Run:
    systemctl list-units --type=service

    This shows all loaded service units, their state (active, inactive, failed), and a short description. The list is paginated; press Space to scroll down and q to quit.

  3. List all services, including ones not loaded. The default only shows loaded units. To see every service file on the system (including those not currently active), run:
    systemctl list-unit-files --type=service

    This shows the state of each service file (enabled, disabled, static, masked) which tells you if it starts at boot.

  4. Filter by state. You can combine with --state to show only services in a specific state. For example, to list only running services:
    systemctl list-units --type=service --state=running

    For failed services (useful for troubleshooting):

    systemctl list-units --type=service --state=failed

    You can also use --state=exited (services that ran and finished), --state=dead, or --state=inactive.

  5. List only enabled or disabled services. To see which services are enabled to start at boot, use:
    systemctl list-unit-files --type=service --state=enabled

    For disabled ones, replace enabled with disabled.

  6. Get more details with a custom output. If you need more columns (like the load state or the unit file path), use the --output= option. For example, to get a full, machine-readable output:
    systemctl list-units --type=service --output=json

    Or to see everything including the description and load state:

    systemctl list-units --type=service --all --output=json
  7. Check a specific service. To see the status of one service (e.g., sshd), run:
    systemctl status sshd

    This shows whether it’s active, its PID, memory usage, and recent log lines.

  8. Use grep to filter. If you’re looking for a specific keyword, pipe the output to grep. For example, to find all services with “ssh” in the name:
    systemctl list-units --type=service | grep ssh

Common Mistakes

  • Forgetting --type=service. Without it, systemctl list-units shows all unit types (services, sockets, timers, mounts, etc.), which can be overwhelming.
  • Using service --status-all instead. The old service command works on SysV init and may not show systemd services correctly. Stick with systemctl on modern systems.
  • Confusing list-units with list-unit-files. The former shows currently loaded units; the latter shows all unit files on disk, even those not loaded. If a service isn’t in list-units but you know it exists, check list-unit-files.
  • Not using --all to see inactive services. By default, list-units hides inactive units. Use --all to see every loaded unit, including those that are inactive.
  • Running without sudo when you need it. Listing services generally works without sudo, but some operations like systemctl status on a service you don’t own may show partial info. For full details, use sudo systemctl status.

Tips

  • Use --no-pager to avoid the pager. If you want to pipe the output to a file or another command, add --no-pager to prevent the pager from interfering, e.g., systemctl list-units --type=service --no-pager.
  • Combine with --plain for cleaner output. --plain removes the pager and the column headers, making it easier to parse in scripts.
  • Count services. To count how many services are running, use: systemctl list-units --type=service --state=running --no-pager | wc -l (subtract 1 for the header line).
  • Watch the service state. The LOAD column shows “loaded” if the unit file is loaded, “not-found” if missing. The ACTIVE column shows “active” or “inactive”, and SUB gives more detail like “running” or “exited”.
  • Use systemctl list-dependencies to see what a service depends on. This helps understand why a service might not start.

Troubleshooting

“Failed to connect to bus: No such file or directory” – This usually means systemd is not running (e.g., you’re in a container or a very minimal environment). Try ps -p 1 to check. If PID 1 is not systemd, you can’t use systemctl; use the init system’s tools instead.

“Unit sshd.service could not be found.” – The service name might be different (e.g., ssh on some distros). Use systemctl list-unit-files | grep ssh to find the exact name.

Output is cut off or not showing all services. – Remember that list-units only shows loaded units. Use --all to see all loaded, or list-unit-files to see all files. Also, the pager may truncate lines; use --no-pager or increase terminal width.

“Failed to get properties: No such interface” – This can happen when using systemctl status on a service that is not a systemd service (e.g., a SysV init script). It’s rare; try systemctl list-units --type=service | grep <name> to see if it’s actually a service.

Permission denied when listing unit files. – Some unit files might be in read-only locations. Use sudo to get full access.

Frequently Asked Questions

How do I list all running services?

Run systemctl list-units --type=service --state=running. This shows only services that are currently active and running.

What’s the difference between list-units and list-unit-files?

list-units shows units that are currently loaded into memory (i.e., they’ve been started or are known to the system). list-unit-files shows every unit file on disk, regardless of whether it’s loaded. A service can be in the file list but not in the units list if it hasn’t been started.

How do I list services that are enabled at boot?

Use systemctl list-unit-files --type=service --state=enabled. This shows services with the “enabled” state, meaning they will start automatically at boot.

Can I list services without sudo?

Yes, listing services is generally a read-only operation and works without sudo. However, for some details like the full status of a service (including log lines), you may need sudo to see all information.

How do I list services alphabetically?

The default output is already sorted alphabetically by unit name. If you want to sort by another column, you can pipe to sort, but the default is usually fine.

Why do I see services with a state of “static”?

A “static” service cannot be enabled or disabled directly; it’s typically started by another service or event. For example, systemd-sysctl.service is static because it’s triggered by systemd itself.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →