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
Software Requirements and Conventions Used
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
-
List all services
To list all services unit files execute the bellow command from your terminal:
$ systemctl list-units --all --type=service --no-pager
-
List all available systemd unit files
-
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
-
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
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