systemtl Command in Linux

Learn via video courses
Topics Covered

Overview

The systemctl command is a powerful tool in Linux that enables system administrators to manage system services and units. It is used to start, stop, restart, enable, disable, and reload services and daemons in the system. In this article, we will explore the syntax, options, and usage of the systemctl command.

Linux systemctl Command Syntax

The syntax for the systemctl command is as follows:

Where:

  • OPTIONS: Optional arguments that modify the behavior of the command.
  • COMMAND: The action to be performed on the unit.
  • UNIT: The name of the unit to be acted upon.

systemctl Command Options:

  • -h, --help: Displays a help message and exits.
  • --version: Displays the version number of systemctl and exits.
  • -t, --type: Filters the list of units shown by type.
  • -a, --all: Shows all available units and their states.

Example Usages

  • Start a Service::

    Explanation: This command starts the specified service.

  • Stop a Service::

    Explanation: This command stops the specified service.

  • Restart a Service::

    Explanation: This command restarts the specified service.

  • Enable a Service::

    Explanation: This command enables the specified service to start automatically on boot.

  • Disable a Service::

    Explanation: This command disables the specified service from starting automatically on boot.

  • Check the Status of a Service::

    Explanation: This command shows the status of the specified service.

Tips

  • You must have superuser privileges to run the systemctl command.

  • You can also use the systemctl command to reload a service without stopping it completely by using the 'reload' command.

Advanced Use Cases of systemctl Command in Linux

  • View All Running Services::

    Explanation: This command lists all currently running services on the system.

  • View Failed Services::

    Explanation: This command displays a list of all services that have failed.

  • Mask a Service::

    Explanation: This command masks the specified service, preventing it from being started manually or automatically.

Conclusion

  • The systemctl command is a powerful tool for managing services and units in Linux.

  • You can use it to start, stop, restart, enable, disable, and reload services and daemons in the system.

  • The systemctl command is essential for system administrators to manage their Linux systems effectively.