In this article you will learn how to list and change state for systemd services and unit files on Ubuntu 20.04 Focal Fossa Linux Server/Desktop.

In this tutorial you will learn:
  • How to list services and unit files
  • How to list running/exited/dead services
  • How to list enabled/disabled services
Ubuntu 20.04 list running services
Ubuntu 20.04 list running services

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Installed Ubuntu 20.04 or upgraded Ubuntu 20.04 Focal Fossa
Software systemd
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

Ubuntu 20.04 list services by example

  1. List all services

    To list all services unit files execute the bellow command from your terminal:
    $ systemctl list-units --all --type=service --no-pager
    
  2. List all available systemd unit files

  3. The following command will display all available systemd unit files regardless of their state and type:
    $ systemctl list-unit-files --no-pager
    
    Use the grep command in case you are searching for a specific unit file. For example the bellow command will search for an apache2 unit file:
    $ systemctl list-unit-files --no-pager | grep apache2
    

    SUBSCRIBE TO NEWSLETTER
    Subscribe to Linux Career NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


  4. List all active running/exited/dead services

    The systemctl command can be used to list all active running services:
    $ systemctl list-units --all --type=service --no-pager | grep running
    
    To display all exited service execute:
    $ systemctl list-units --all --type=service --no-pager | grep exited
    
    Furthermore, to show all stopped/dead systemd services execute:
    $ systemctl list-units --all --type=service --no-pager | grep dead
    
    You can start and stop services using the systemctl command. For example to start Apache2 service we can execute:
    $ systemctl start apache2
    
    Conversely, to stop service execute:
    $ systemctl stop apache2
    
  5. List enabled/disabled systemd service unit file states

    The following systemctl command will list all enabled services on Ubuntu 20.04 Desktop/Server.
    $ systemctl list-unit-files | grep enabled
    
    On the other hand to list all disabled services execute:
    $ systemctl list-unit-files | grep disabled
    
    Enabled services will automatically start after system reboot.

    Use the systemctl command to set the service state as enabled or disabled. For example the following command will enable the Apache2 service to start during the system boot startup:
    $ sudo systemctl enable apache2
    
    Or to disable the service from starting after the system reboot execute:
    $ sudo systemctl disable apache2
    
FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.

You may also be interested in:



Comments and Discussions