Linux shutdown Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, we will explore the Linux shutdown command and learn how to use it to shut down, reboot, or halt the system. We will cover the basic syntax and options of the shutdown command, as well as how to immediately shut down the system and schedule a shutdown at a specific time. This lab will provide practical examples and help you understand the versatility of the shutdown command in system management.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/UserandGroupManagementGroup(["`User and Group Management`"]) linux(("`Linux`")) -.-> linux/SystemInformationandMonitoringGroup(["`System Information and Monitoring`"]) linux/UserandGroupManagementGroup -.-> linux/sudo("`Privilege Granting`") linux/SystemInformationandMonitoringGroup -.-> linux/time("`Command Timing`") subgraph Lab Skills linux/sudo -.-> lab-422918{{"`Linux shutdown Command with Practical Examples`"}} linux/time -.-> lab-422918{{"`Linux shutdown Command with Practical Examples`"}} end

Understand the Linux shutdown Command

In this step, we will explore the Linux shutdown command and understand its various options and usage.

The shutdown command is a powerful tool in Linux that allows you to shut down, reboot, or halt the system. It provides several options to control the shutdown process, such as scheduling a shutdown at a specific time or immediately shutting down the system.

Let's start by understanding the basic syntax of the shutdown command:

sudo shutdown [options] [time] [message]

Here's a breakdown of the different options:

  • [options]: Specifies the action to be performed, such as shutting down, rebooting, or halting the system.
  • [time]: Specifies the time when the shutdown should occur. This can be a specific time (e.g., 16:20) or a delay in minutes (e.g., +10).
  • [message]: Allows you to provide a message that will be displayed to all logged-in users before the shutdown occurs.

Now, let's explore some common shutdown command options:

sudo shutdown -h now      ## Shut down the system immediately
sudo shutdown -r now     ## Reboot the system immediately
sudo shutdown -h +10     ## Shut down the system in 10 minutes
sudo shutdown -c         ## Cancel a scheduled shutdown

Example output:

Shutdown scheduled for Fri 2023-04-28 12:00:00 UTC, use 'shutdown -c' to cancel.

In the next steps, we will cover more advanced usage of the shutdown command, including scheduling a shutdown at a specific time.

Shut Down the System Immediately

In this step, we will learn how to immediately shut down the system using the shutdown command.

To shut down the system immediately, we can use the shutdown command with the -h (halt) option and the now argument:

sudo shutdown -h now

This will immediately initiate the shutdown process, and the system will power off once the shutdown is complete.

Example output:

Shutdown scheduled for Fri 2023-04-28 12:00:00 UTC, use 'shutdown -c' to cancel.

You can also use the poweroff command, which is an alias for shutdown -h now:

sudo poweroff

This will have the same effect as using the shutdown -h now command.

If you need to cancel a scheduled shutdown, you can use the shutdown -c command:

sudo shutdown -c

This will cancel the scheduled shutdown.

Schedule a Shutdown at a Specific Time

In this step, we will learn how to schedule a system shutdown at a specific time using the shutdown command.

To schedule a shutdown at a specific time, you can use the shutdown command with the [time] argument. The time can be specified in various formats, such as a 24-hour time (e.g., 16:20) or a delay in minutes (e.g., +10).

Here are some examples:

sudo shutdown 16:20     ## Shut down the system at 4:20 PM
sudo shutdown +10       ## Shut down the system in 10 minutes

You can also provide an optional message that will be displayed to all logged-in users before the shutdown occurs:

sudo shutdown 16:20 "System maintenance in progress, please save your work."

Example output:

Shutdown scheduled for Fri 2023-04-28 16:20:00 UTC, use 'shutdown -c' to cancel.

To cancel a scheduled shutdown, you can use the shutdown -c command:

sudo shutdown -c

This will cancel the scheduled shutdown.

Summary

In this lab, we explored the Linux shutdown command and learned how to shut down the system immediately and schedule a shutdown at a specific time. We understood the basic syntax of the shutdown command and its various options, such as shutting down, rebooting, or halting the system. We also learned how to cancel a scheduled shutdown. By using the shutdown -h now command, we can immediately initiate the shutdown process and power off the system. Additionally, we explored how to schedule a shutdown at a specific time using the shutdown command with the appropriate time argument.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like