Systemd is the default init system for most modern Linux distributions, including Ubuntu, CentOS, Fedora, and Debian. It plays a crucial role in managing system services and processes. To harness the power of systemd, you need to become familiar with the
systemctl command. In this blog post, we’ll explore essential
systemctl commands to manage a service running on a Linux system.
systemctl is a command-line tool for controlling the systemd system and service manager. It allows you to manage system services, inspect their status, start, stop, enable, or disable them, among other things. This tool simplifies sysadmin tasks, making it easier to maintain a healthy Linux system.
How to List All Enabled and Disabled Services
To get an overview of all services on your system, both enabled and disabled, you can use the following command:
systemctl list-unit-files -at service
This command provides a comprehensive list of services, their statuses, and whether they are set to start automatically during boot.
How to List All Services and Their Statuses
To see a detailed list of all services and their current statuses, including active, inactive, and failed services, use the following command:
systemctl list-units -at service
This command gives you a real-time snapshot of the status of all services on your system.
How to List Running Services
If you want to view only the services that are currently running, you can filter the list using this command:
systemctl list-units -at service --state=running
This is particularly useful when you need to identify which services are actively using system resources.
How to Display the Content of a Service File
To examine the content of a service file, such as the configuration for the rsyslog service, use the
systemctl cat rsyslog
This command displays the contents of the service file, making it easier to understand its configuration.