Development

How to Shutdown and Reboot From the Terminal

Captain Salem 2 min read

How to Shutdown and Reboot Computer From the Terminal

Shutting down a computer allows you to close all programs and turn off the power to the computer’s hardware. Typically, we can achieve this by clicking on the “shutdown” button in the operating system or pressing the power button on the computer.

However, when in the terminal, it can be much more convenient to shut down or reboot from the terminal session. This can be useful when accessing remote systems such as servers over SSH.

This tutorial will discuss how you can use terminal commands to shut down or reboot your system.

Windows Shutdown From Terminal

On Windows, you can use the shutdown command as shown below.

shutdown /s

The command above will shut down the computer immediately.

To specify a specific delay, you can use the /t parameter as shown:

shutdown /s /t 60

In this case, the command will shut down the computer in 60 seconds.

To cancel a scheduled shutdown, use the /a option as:

shutdown /a

This command is useful if you accidentally scheduled a shutdown or reboot and need to cancel it before it happens. Keep in mind that a shutdown or reboot can only be canceled by the user who issued it.

Windows Reboot From Terminal

To reboot your Windows system from the command prompt, run the shutdown command with the /r option.

shutdown /r

This command reboots the system immediately. Similarly, to add a delay, use the /t parameter:

shutdown /r /t 60

In this case, the system will reboot the computer in 60 seconds.

We can also use the /f parameter to forcefully close all running programs and shut down the computer instantly.

shutdown /s /f

macOS Shutdown From the Terminal

On macOS, you can shut down the system from the terminal using the shutdown command:

sudo shutdown -h now

This will the system immediately.

You can also use the -h parameter to specify a delay in minutes before shutting down. Example

sudo shutdown -h +5

macOS Reboot From Terminal

On macOS, to reboot from the terminal, use the -r option:

sudo shutdown -r now

This command should reboot the system immediately.

To cancel a scheduled reboot or shutdown on macOS, use the -c option:

sudo shutdown -c

Linux Shutdown From Terminal

SImilarly, we can use the shutdown command in Linux to shutdown the system. Example:

sudo shutdown -h now
sudo shutdown now

This should shut down the system immediately.

To specify a shutdown delay, use the -h option and specify a delay in minutes:

sudo shutdown -h +5

This will shut down the system after 5 minutes.

To reboot, use the -r option:

sudo shutdown -r now
sudo reboot now

The command above should terminate reboot the system immediately.

You can also specify a specific time on which you wish the system to shutdown as shown:

sudo shutdown -h 03:30

This will allow the system to shutdown at 03:30

To cancel a scheduled shutdown or reboot, use the -c option:

sudo shutdown -c

Keep in mind that the shutdown and reboot commands require sudo or root permissions.

Before shutting down or rebooting a system, always ensure to close any open work and close any programs or services running on the system to avoid data loss.

Conclusion

In this post, you discovered the various ways you can perform a shutdown and reboot from the terminal of various systems, including Windows, macOS, and Linux.

Share
Comments
More from Cloudenv

Cloudenv

Developer Tips, Tricks and Tutorials.

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to Cloudenv.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.