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]
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.
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.
Similar Readings
- The “time” Command in Linux [4 Practical Examples]
- The “tty” Command in Linux [4 Practical Examples]
- The “uptime” Command in Linux [5 Practical Examples]
- The “vmstat” Command in Linux [6 Practical Examples]
- The “uname” Command in Linux [11 Practical Examples]
- The “apt-get” Command in Linux [10 Practical Examples]
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.
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.
Similar Readings
- The “free” Command in Linux [8 Practical Examples]
- The “getent” Command in Linux [11 Practical Examples]
- The “groupadd” Command in Linux [7 Practical Examples]
- The “addgroup” Command in Linux [7 Practical Examples]
- The “groups” Command in Linux [6 Practical Examples]
- The “firewall-cmd” Command in Linux [7 Practical Examples]
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.
Similar Readings
- The “groupmod” Command in Linux [5+ Practical Examples]
- The “id” Command in Linux [7+ Practical Examples]
- The “passwd” Command in Linux [7 Practical Examples]
- The “sestatus” Command in Linux [4 Practical Examples]
- The “shutdown” Command in Linux [7 Practical Examples]
- The “finger” Command in Linux [6 Practical Examples]
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.
Similar Readings
- The “dmesg” Command in Linux [7+ Practical Examples]
- The “install” Command in Linux [6+ Practical Examples]
- The “reboot” Command in Linux [3 Practical Examples]
- The “sync” Command in Linux [8 Practical Examples]
- The “chage” Command in Linux [7 Practical Examples]
- The “env ” Command in Linux [9 Practical Examples]
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.
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
- The “sudo” Command in Linux [8 Practical Examples]
- The “df” Command in Linux [11 Practical Examples]
- The “apt” Command in Linux [13+ Practical Examples]
- The “top” Command in Linux [8 Practical Examples]
- The “htop” Command in Linux [7 Practical Examples]
- The “enable” Command in Linux [6 Practical Examples]
FUNDAMENTALS A Complete Guide for Beginners