This post pens down the use of the “systemctl” command in Ubuntu 22.04 with the following guidelines:
- How to Use systemctl in Ubuntu?
How to Use systemctl in Ubuntu?
The working of the “systemctl” command relies on its syntax.
The generalized syntax of the “systemctl” command is written here:
The above syntax contains the following parameters:
- systemctl: Represents the main “systemctl” command.
- Options: Helps to get the desired output.
- Command Name: Specifies the service commands.
Let’s see the practical implementation of the above syntax for controlling “systemd” services.
Systemctl Enable Services
The “enable” service tool is used as a command with the “systemctl” to enable the particular service in Ubuntu:
Note: The “systemctl” command needs the superuser privileges, i.e., “sudo” to deal with the system services.
The “cron” service has been enabled now permanently.
Systemctl Disable Services
To disable, use the “systemctl” command with the “disable” option as seen below:
The output shows that the “cron” service has been disabled permanently and will never enable after the boot.
Systemctl Start Services
The service command “start” alongside the “systemctl” starts the services temporarily. It will go back into the previous status after booting up:
The “apache2” service has been started and is ready to use.
Systemctl Stop Services
Use the “stop” with the “systemctl” tool to stop the specified service for a short interval of time (temporarily):
Systemctl Show Services Status
For checking the current working status and details of the services, execute the “systemctl” command combined with the “status/show” service utility:
The “apache2” service is enabled but stopped temporarily.
Systemctl Active Units List
The “systemd” uses the “units” which generally manage and control the task/action. Execute the “systemctl” command followed by the “list-units” service command and the “type” flag in this way:
Systemctl Specific Units State
Instead of all active units list the user can also list down the specified state of the units using the “state” flag of the “systemctl” command:
The active “systemd” units having existing status have been displayed in the terminal.
In Ubuntu, the “systemctl” command is used to control and manage the “systemd” services with a combination of service commands. The service command includes “start”, “stop”, “enable”, “disable”, and “status” to manage, change, and check the status of the “systemd” services. This guide has enlisted a brief detail of the objective and usage of the “systemctl” command.