Using systemctl command in Linux
 

Using systemctl command in Linux

 

The systemctl command in Linux is responsible for controlling a widely adopted “systemd” init system and service manager. The init is the first process that starts when you power on your Linux system.

The systemd is a newer init system whose primary purpose is initializing, managing, and tracking system services and daemons. It replaces the traditional sys v init system and nowadays adopted by the majority of Linux distributions.

In this article, we will discuss the usage of systemctl command in Linux with some examples.

Syntax of the systemctl command

How to use systemctl on a Linux system, the syntax is given below –

systemctl [options..] command [unit..]

You can find a detailed list of options on the command’s man page.

List all the running units

A unit file contains the information of a service, socket, device, mount point, partition, swap file, a start-up target, or a group of externally created processes. To list all units in your system use the following command in your terminal –

systemctl

Now see the output of this command –

Check whether a unit or service is running or not

You can check whether a unit or service is running or not by executing the following command in your terminal –

systemctl status service-name

For example –

systemctl status mysql.service

As you can see in the image the mysql service is active and running.

How to start a service

To start a service in your system use the following command in your terminal –

sudo systemctl start service-name

Replace the service-name with yours. Once this command gets executed successfully you can verify that the service is started or not by checking its status.

How to stop a service

Now if you want to stop a service that is currently running, use the given command in your terminal –

sudo systemctl stop service-name

Again you can verify the service is stopped or not by checking its status.

Enabling or disabling a service on Linux

When you enable a service it starts automatically when you start your system next time. Now use the following command to enable a service on your system.

sudo systemctl enable service-name

Similarly, you can disable a service if you want by using –

sudo systemctl disable service-name

Check if a service is enabled or not

After enabling service in your system you can check if the service is enabled or not by using –

sudo systemctl is-enabled service-name

For example –

sudo systemctl is-enabled mysql.service

How to restart a service

Sometimes you need to restart a running service after making changes in its configuration file you can do this by using –

sudo systemctl restart service-name

You can find more information about systemctl on its manual page. Now execute the given command to see its manual page in your terminal –

man systemctl

How to analyze systemd boot process

The systemd-analyze is also a systemd utility command that helps in tracking down the process execution time on a Linux system.

You can analyze the systemd boot process by using the following command in your terminal –

systemd-analyze

As you can see in the image the total time taken by the system to boot is 1min 6.278s.

To find how much time is taken by each process while system boot, use –

systemd-analyze blame

A list of processes and in how much time they are executed will be displayed in your terminal.

Conclusion

This is how you can use the systemctl command on your Linux system. Now if you have a query then leave it in the comments below.

Previous [xubuntu] pantalla negra
Next Bluray Drive no longer recognized after DVD Backup + VLC install
 

About author

You might also like

Commands 0 Comments

Using whois command in Linux

This post was last updated on January 16th, 2021 at 12:13 pmWhois command in Linux searches in a WHOIS database. This database stores the registered users of an internet resource

Commands 0 Comments

Using rm command to delete files and directories in Linux

As already we have discussed how to create a file or directory in Linux or Unix systems. Now if you want to remove them then Linux provides a separate command

Linux Topics 0 Comments

Top Command Usage With Example In Linux/Unix

This post was last updated on August 1st, 2020 at 08:47 pmThe top is one of the most frequently used command in Unix like operating systems for the administrative tasks.

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply