How to use the command 'shutdown' (with examples)

How to use the command 'shutdown' (with examples)

  • Osx
  • December 25, 2023

The ‘shutdown’ command is a useful command that allows you to control the power state of a system. It can be used to power off (halt) the system immediately, put the system to sleep, or restart the system. It also provides options to schedule power off or reboot operations at specific times. This article will illustrate each of these use cases of the ‘shutdown’ command.

Use case 1: Power off (halt) immediately

Code:

shutdown -h now

Motivation: This command is useful when you want to immediately power off the system.

Explanation: The ‘-h’ option stands for halt, which means to power off the system. The ’now’ indicates that the action should be performed immediately.

Example output:

The system immediately shuts down and powers off.

Use case 2: Sleep immediately

Code:

shutdown -s now

Motivation: This command is useful when you want to put the system to sleep immediately.

Explanation: The ‘-s’ option stands for sleep. The ’now’ indicates that the action should be performed immediately.

Example output:

The system goes into sleep mode.

Use case 3: Reboot immediately

Code:

shutdown -r now

Motivation: This command is useful when you want to immediately reboot the system.

Explanation: The ‘-r’ option stands for restart. The ’now’ indicates that the action should be performed immediately.

Example output:

The system immediately reboots.

Use case 4: Reboot in 5 minutes

Code:

shutdown -r "+5"

Motivation: This command is useful when you want to schedule a system reboot after a specific delay. In this example, we schedule the reboot 5 minutes from now.

Explanation: The ‘-r’ option stands for restart. The ‘+5’ indicates the delay in minutes before rebooting.

Example output:

The system displays a notification that it will be rebooted in 5 minutes.

Use case 5: Power off (halt) at 1:00 pm (Uses 24h clock)

Code:

shutdown -h 1300

Motivation: This command is useful when you want to schedule a power off (halt) operation at a specific time. In this example, we schedule the power off at 1:00 pm.

Explanation: The ‘-h’ option stands for halt. The ‘1300’ indicates the time in 24-hour format.

Example output:

The system displays a notification that it will be powered off at 1:00 pm.

Use case 6: Reboot on May 10th 2042 at 11:30 am (Input format: YYMMDDHHMM)

Code:

shutdown -r 4205101130

Motivation: This command is useful when you want to schedule a system reboot at a specific date and time. In this example, we schedule the reboot on May 10th 2042 at 11:30 am.

Explanation: The ‘-r’ option stands for restart. The ‘4205101130’ indicates the date and time in YYMMDDHHMM format.

Example output:

The system displays a notification that it will be rebooted on May 10th 2042 at 11:30 am.

Conclusion:

The ‘shutdown’ command provides a convenient way to control the power state of a system. Whether you need to power off, put the system to sleep, or reboot, the ‘shutdown’ command has you covered. Additionally, it allows you to schedule power off or reboot operations at specific times, providing flexibility and convenience. With these examples, you can effectively utilize the ‘shutdown’ command to meet your system power management needs.

Related Posts

How to use the command 'dvc unfreeze' (with examples)

How to use the command 'dvc unfreeze' (with examples)

The ‘dvc unfreeze’ command is used to unfreeze stages in the DVC (Data Version Control) pipeline.

Read More
How to use the command "yum" (with examples)

How to use the command "yum" (with examples)

The “yum” command is a package management utility specifically designed for use in RHEL (Red Hat Enterprise Linux), Fedora, and CentOS distributions.

Read More
Using the dmesg Command (with examples)

Using the dmesg Command (with examples)

The dmesg command in Unix-like operating systems is used to display kernel messages.

Read More