systemctl

system administrationLinux
The systemctl command is one of the most frequently used commands in Linux/Unix-like operating systems. systemctl Control the systemd system and service manager

Quick Reference

Command Name:

systemctl

Category:

system administration

Platform:

Linux

Basic Usage:

systemctl [options] [arguments]

Common Use Cases

    Syntax

    systemctl [options] command [name...]

    Options

    Option Description
    -t, --type= List units of a specific type
    --state= List units with specific state
    -a, --all Show all loaded units
    -l, --full Don't ellipsize unit names, process tree, etc.
    --fail Show failed units only
    --show-types Show types in list-units/list-sockets
    -i, --ignore-inhibitors When shutting down or sleeping, ignore inhibitors
    --no-block Do not wait until operation finished
    --no-wall Don't send wall message before halt/power-off/reboot
    --no-pager Do not pipe output into a pager
    --system Connect to system manager
    --user Connect to user service manager
    --now When enabling/disabling a unit, also start/stop it
    -q, --quiet Suppress output
    -p, --property= Show only properties specified by a list
    -H, --host= Operate on remote host
    -M, --machine= Operate on local container
    -h, --help Show help
    --version Show version

    Examples

    How to Use These Examples

    The examples below show common ways to use the systemctl command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    Basic Examples:

    Start a service
    systemctl start apache2.service
    Stop a service
    systemctl stop apache2.service
    Restart a service
    systemctl restart apache2.service
    Show status of a service
    systemctl status apache2.service
    Enable a service to start at boot
    systemctl enable apache2.service
    Disable a service from starting at boot
    systemctl disable apache2.service

    Advanced Examples:

    Check if a service is currently active
    systemctl is-active nginx.service
    Check if a service is enabled
    systemctl is-enabled nginx.service
    Show all running services
    systemctl list-units --type=service --state=running
    Show all services that failed to start
    systemctl list-units --type=service --state=failed
    Reload a service's configuration without restarting
    systemctl reload nginx.service
    Reload systemd manager configuration
    systemctl daemon-reload
    Reboot the system
    systemctl reboot
    Power off the system
    systemctl poweroff
    View service dependencies
    systemctl list-dependencies nginx.service
    Show properties of a service
    systemctl show nginx.service
    Show specific property of a service
    systemctl show -p Conflicts nginx.service
    Edit a service unit file
    systemctl edit nginx.service
    Create a new service with an override file
    systemctl edit --full myservice.service
    Mask a service (prevent it from being started)
    systemctl mask nginx.service
    Unmask a service
    systemctl unmask nginx.service
    List timer units
    systemctl list-timers --all
    Check system boot logs
    systemctl --no-pager --full list-units
    Get a tree of running units
    systemctl list-dependencies
    Show system status
    systemctl status
    List all loaded unit files
    systemctl list-unit-files
    Check available system targets
    systemctl list-units --type=target --all

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The `systemctl` command is the primary interface for managing services and controlling the systemd system and service manager in modern Linux distributions. It allows administrators to start, stop, restart, enable, disable, and check the status of services, among many other functions. Systemd is an init system and system manager that has become the default in most major Linux distributions, replacing the traditional SysV init scripts. It was designed to overcome limitations in the older init systems, offering features like parallel startup of services, on-demand service activation, dependency tracking between services, and more comprehensive service management. The `systemctl` command manages "units," which are resources that systemd knows how to manage. The most common type of unit is a "service" (ending in .service), but there are other types like socket, device, mount, automount, target, path, timer, and more. Some of the most commonly used `systemctl` operations include: 1. **Service control**: Start, stop, restart, and reload services. - `systemctl start `: Starts a service immediately. - `systemctl stop `: Stops a running service. - `systemctl restart `: Stops and then starts a service. - `systemctl reload `: Reloads configuration without stopping. 2. **Boot-time service configuration**: - `systemctl enable `: Configure a service to start at boot time. - `systemctl disable `: Prevent a service from starting at boot time. 3. **Service information**: - `systemctl status `: Shows the current status of a service, including whether it's running, recent log entries, and other details. - `systemctl is-active `: Returns the current state of a service. - `systemctl is-enabled `: Checks if a service is configured to start at boot. 4. **System state control**: - `systemctl reboot`: Reboot the system. - `systemctl poweroff`: Shut down the system. - `systemctl suspend`: Suspend the system. - `systemctl hibernate`: Hibernate the system. 5. **Configuration management**: - `systemctl daemon-reload`: Reload the systemd manager configuration. - `systemctl edit `: Edit a service's override configuration. Unit files that define services and other systemd resources are typically stored in `/etc/systemd/system/` (for system-specific configurations), `/run/systemd/system/` (for runtime configurations), and `/usr/lib/systemd/system/` (for package-provided defaults). The `systemctl` command has largely replaced older service management commands like `service`, `chkconfig`, and `update-rc.d` in modern Linux distributions, providing a unified interface for service management across different distributions that use systemd.

    Related Commands

    These commands are frequently used alongside systemctl or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the systemctl command works in different scenarios.

    $ systemctl
    View All Commands