Systemd and units

What are units?

Units are basically resources that can be managed by systemctl, each unit is defined by unit files which are generally located in /lib/systemd/system

To know more about systemctl refer to previous article at

The type of unit is defined by the last part of unit file-name for example services have .service suffix

Note: we are not using sudo during execution of commands that’s because we are just read file info but not making any changes

Systemd will only read or parse units which are necessary, it might not read every unit file in its directory so while listing units it only show files that are loaded into memory

Listing current units

To list all the units that are currently active you can use list-units command

systemctl list-units



To list all the units regardless of their current state you can use — all flag with it

systemctl list-units — all

To list units of particular type you can use — type= filter for example to list all services unit

systemctl list-units — type=service

Listing All unit files

To list all unit files in the current directory of systemd we use list-unit-files command .

systemctl list-unit-files

The first thing to note here is that it contains a lot less information as compared to list-unit command. The reason is obvious: these are files which might not be loaded by systemd hence it only presents info about unit files.

Displaying unit file of a service

To get more specific information about a particular service we can use cat command to display its unit file

systemctl cat apache2.service

List dependencies of unit

To list dependencies of a unit you can use list-dependencies command. It will output list of dependencies of unit which must be completed before starting that unit

Masking of units

In the last article we saw how we can use systemctl enable/disable servicename command to enable or disable a service but systemd has the ability to make a unit completely unstartable by masking it. To mask a service use

sudo systemctl mask apache2.service

This will make apache unstartable automatically or manually, If you want to again use service you will have to unmask the service first using

sudo systemctl unmask apache2.service



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store