The “service” Command in Linux [6 Practical Examples]

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

Services are the processes that run in the background and are launched during system bootup. Managing these services is a general task for Linux users. The service command in Linux is mainly used for starting, stopping, and restarting services on our operating system. This command is very versatile in controlling our system services.

A. Description

The service command in Linux is mainly used to manage system services while using the Linux operating system.

B. Syntax

The service command in Linux is a command that takes OPTIONS, Service_Name, and COMMAND  as its argument. The general syntax for the service command is given below.

service [OPTIONS] [Service_Name] [COMMAND]
Note: The  Service_Name means the process running in the operating system, and COMMAND is the specific task you want to do. Here, the OPTIONS, Service_Name, and COMMAND are enclosed by square brackets, meaning that OPTIONS, Service_Name, and COMMAND are not always mandatory for the command.

C. Options

Some options are available to use with the service command to modify the command. I have listed these options below. If you want to find out more about your desired options, you can look for it on the man (manual) page. To go to the man page, input the following command into the terminal and tap ENTER.

man service

Useful Options

  • –status-all: It prints all available services on the terminal.
  • –help/-h: It prints the help section of the service command.
  • –version: It shows the version of the service command.
Note: All options in Linux are case-sensitive. Therefore, you must be careful while using these.

Practical Examples of the “service” Command in Linux

The service command in Linux is helpful in controlling any service on the operating system. Moreover, the service command in Linux has many practical implementations, and I have illustrated a few of them below.

Example 1: Listing All the Services Using the “service” Command in Linux

You can list all the services available using the –status-all option along with the service command. Here I will print all the services available on the terminal. To do so, follow the procedures below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

service --status -all

➌ Now, press the ENTER button.

Output >

All available services are printed on the terminal, as depicted below. Here, plus(+) sign means active services, and the minus() sign means inactive services.All available services are printed on the terminal.


Similar Readings


Example 2: Starting a Particular Service Using the “service” Command in Linux

The service command can start a particular service. Here, I will start the rsync service. To achieve this, follow the steps described below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Run the following command in the command prompt.

service rsync start

➌ Now, tap the ENTER button.

Output >

The following image shows that the service command has started the rsync process.The service command in Linux has started the rsync process.

Example 3: Stopping a Particular Service Using the “service” Command in Linux

You can stop a particular service using the service command. Here I will stop the rsync service. To do this task, follow the steps given below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Copy the following command in the command prompt:

service rsync stop

➌ Now, tap the ENTER button.

Output >

The following image shows that the service command has stopped the rsync process.The service command in Linux has stopped the rsync process.


Similar Readings


Example 4: Restarting a Particular Service Using the “service” Command in Linux

The service command can restart a particular service. Here I will restart the rsync service. To do this task, follow the procedures mentioned below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Copy the following command in the command prompt:

service rsync restart

➌ Now, press the ENTER button.

Output >

The service command in Linux has restarted the rsync process, as depicted in the following image.The service command in Linux has restarted the rsync process.


Similar Readings


Example 5: Getting the Status of a Particular Service Using the “service” Command in Linux

You can know about the status of a particular process using the service command. Here I will find the status of the rsync service. To do the same, follow the below procedures.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Input the following command in the command prompt:

service rsync status

➌ Now, press the ENTER button.

Output >

The service command displays the status of rsync process as depicted in the following image.The service command displays the status of rsync process.


Similar Readings


Example 6: Getting the Version of the “service” Command in Linux

You can easily learn about the version of the service command. Here, I will get the version of the service command. To do the same task, follow the procedures mentioned below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the terminal.

service --version

➌ Now, tap the ENTER button.

Output >

The terminal shows the version of the service command, as shown in the following image.The terminal shows the version of the service command.

Conclusion

In this article, I have demonstrated the controlling of services on the system in various ways using the service command in Linux. I hope you’ll be competent enough to explore more things with the help of these practical examples.


Similar Readings

Rate this post
Susmit Das Gupta

Hello everyone. I am Susmit Das Gupta, currently working as a Linux Content Developer Executive at SOFTEKO. I am a Mechanical Engineering graduate from Bangladesh University of Engineering and Technology. Besides my routine works, I find interest in going through new things, exploring new places, and capturing landscapes. Read Full Bio

Leave a Comment