Whether it’s for an SSH Ubuntu server or because your mouse stopped working, learning how to use Linux
shutdown commands on the command line works wonders for everybody. Here we show you how to master the
shutdown command to quickly shut down your PC.
- What's a Shutdown Command?
- How to Use Shutdown Commands
- 1. Basic Shutdown Command
- 2. Shutdown without Power Off
- 3. Shutdown with Power Off
- 4. Shutdown after X Minutes
- 5. Shutdown at a Certain Time
- 6. Send a Warning Message Before Shutdown
- 7. Basic Restart Command
- 8. Forced Shutdown Commands
- Bonus: Cancel a Shutdown Command
- Frequently Asked Questions
Tip: Learn the differences between Shut down, hibernate or Sleep.
What’s a Shutdown Command?
On Linux, there are two ways to turn your PC off (three if pulling the plug counts):
- Pressing the shutdown button
- Shutting down via the Terminal.
While it might be a hassle trying to access Terminal first before shutting down, it’s actually pretty useful, especially for shutting down a remote Linux PC or server through SSH.
shutdown command turns your PC off much like the shut down button on the system tray does. But it gets even better: it has options that lets you choose when to turn off, among other things.
How to Use Shutdown Commands
The format goes like this:
sudo shutdown <optional setting flag> <shutdown time> <optional message>
Like most system-level commands on Linux, you’ll need
sudo to make this work. And then you can choose an option flag and other options. We’ll go through each one throughout this article.
1. Basic Shutdown Command
shutdown command starts the shutdown process that kills all ongoing applications before powering off. This requires a time setting – you need to tell it when to shut down before it works. By adding
now next to shutdown, you’re telling your PC to stop everything it’s doing and shut down immediately.
sudo shutdown now
You can also link an automatic shutdown shortcut to this command and make a DIY shutdown button. It’s a useful command for SSH servers because it’s super simple to remember. However, some Linux distros and versions might require you to add either a
-P flag to work.
Good to know: You can check the shutdown and reboot dates on your Linux PC easily with these tips.
2. Shutdown without Power Off
sudo shutdown -h now
There are times when it’s better to turn the computer off without taking out the power. The
halt command does everything that the
shutdown command does minus the final step – cutting power out from the system. This works great for when you have self-contained peripherals that take a longer time to turn off than the main computer.
However, you’re better off using the
shutdown command with the
-h flag. This is because
shutdown allows you to set when to turn off the PC, which we’ll get into in a bit.
3. Shutdown with Power Off
sudo shutdown -P now
When your Linux PC or server is on a different room, having to physically press the power button would be pretty problematic. Luckily,
sudo poweroff lets you automatically kill all power to the computer so your CPU would be safe from power surges and other power-related things that could break it.
Still, the best Linux shutdown command to use would be the
shutdown command with the
-P flag. Just remember that it needs a capitalized “P” and not a small one.
4. Shutdown after X Minutes
sudo shutdown +<minutes>
Suppose you had a process that would end in 30 minutes. Maybe you’re downloading something and you think it’ll be done at around that time. You can try replacing
now with a
+ and how much longer you’d want it to wait in minutes before shutting down. For example:
sudo shutdown +30 shuts the computer down after 30 minutes.
Remember that this does not wait for any processes to end before working, so if your task takes a little longer than it should, this Linux shutdown command will turn your PC off as soon as the countdown finishes.
5. Shutdown at a Certain Time
sudo shutdown <hour>:<minute>
If you’re like me who falls asleep on the keyboard at 3am and wakes up to a warm PC that’s been playing music from YouTube all night, you’d be wishing there was a way to turn it off after a certain time. Luckily,
shutdown lets you pick a time, too.
For example, using
sudo shutdown -P 2:45 shuts your Linux PC down as soon as it reaches 2:45 AM. It reads time using the 24-hour format, so you’ll need to type
sudo shutdown -P 14:45 if you want to turn it off at 2:45 in the afternoon.
6. Send a Warning Message Before Shutdown
sudo shutdown <time> "<message>"
When you’re running a Linux server with multiple users connected, it will be good to send a message out to inform everyone about the shutdown. By adding something in “quotation marks”, the Linux server can relay a custom message to other users via the command line.
For automated shutdown and restart functions on servers, this message can be really important. You can add this to a script that runs upon boot. That way, your Linux server can automatically shut down for scheduled maintenance or update.
7. Basic Restart Command
sudo shutdown -r now
By using the
-r flag, you can make your PC reboot instead of powering down. You can replace
now with the time to make a scheduled shutdown, which works great for automatic systems and servers with nightly updates.
Alternatively, there’s the
sudo reboot command, but this one doesn’t allow you setting the time. It works the same as
sudo shutdown -r now for the most part.
Tip: It is good to reboot your PC after updating your Linux kernels.
8. Forced Shutdown Commands
sudo poweroff -f
sudo halt -f
sudo shutdown -f
It’s not everyday when you get a system that just becomes unresponsive to the point that most commands won’t work. The
shutdown commands can take the
-f flag to force a shut down. This is basically the electronic version of a power switch – it’ll force-kill all tasks and shut down.
Only use this for when normal shutdown and restart commands don’t work. You’re bound to lose data (and system integrity) whenever you use this.
Bonus: Cancel a Shutdown Command
sudo shutdown -c
Suppose you made a mistake and wanted to cancel a scheduled
shutdown command. Neither Ctrl + C nor typing
exit on the command line would stop it.
shutdown command has a
-c option which tells the system to cancel whatever time it was that you planned to shut it down.
Frequently Asked Questions
Do Linux shutdown commands break apps?
The shutdown command will not break apps, but if you have unsaved files, then the changes will be lost when the system shut down.
Why do I need to type "sudo" every time I enter a shutdown command on Linux?
The shutdown command is a system level app, that is why it requires the super user privileges to run.
Do Linux shutdown commands work on Windows?
shutdown command only works in Linux. For Windows, you can make use of these tips to shut it down remotely.
Can I turn off my PC before a scheduled shutdown?
A scheduled shutdown is only there to work when the conditions are met. You can safely turn your PC off at any time before the scheduled shutdown.
Image credit: human hand press shutdown button on virtual screen by 123RF. Screenshot by Terenz Jomar Dela Cruz
Our latest tutorials delivered straight to your inbox