Whether it's an Ubuntu SSH server or a mouse that's not working, learning how to use Linux shutdown commands from the command line works wonders for everyone. Here, we'll show you how to master the shutdown command to quickly shut down your computer. In this article, we'll explore useful Linux shutdown commands for restarting or shutting down a Linux computer.
Tip: Get to know Differences between shutdown, hibernation, or sleep.
What is a shutdown order?
On Linux, there are two ways to shut down your computer (three if you pull the plug):
- Press the close button
- Closing through the station.
While it can be a hassle to try to access the Terminal first before shutting down, it's actually very useful, especially for shutting down a remote Linux computer or server via SSH.
The Shutdown command shuts down your computer just like the Shutdown button in the system tray does. But it gets even better: it includes options that let you choose when to shut down, among other things.
How to use shutdown commands
The format goes as follows:
sudo shutdown
Like most system-level commands in Linux, you will need to sudo
To make this work, you can then select the check mark and other options. We'll go over each one in this article.
1. Basic closing order
The order begins shutdown
A shutdown process that kills all running applications before shutting down. This requires setting a timer – you need to tell it when to shut down before it will work. By adding now
After you shut down, you tell your computer to stop whatever it is doing and shut down immediately.
sudo shutdown now
You can also associate an automatic shutdown shortcut with this command and create a DIY shutdown button. This is useful for SSH servers because it's very easy to remember. However, some Linux distributions and versions may require you to add a flag. -h
Or -P
for work.
2. Shutdown without power outage
sudo shutdown -h now
Or
sudo halt
There are times when it is better to shut down your computer without interrupting the power. The command halt
With everything it does shutdown
Minus the final step—turning off the power to the system. This works great when you have standalone peripherals that take longer to power down than the main computer.
However, it is better for you to use the command shutdown
With the mark -h
This is because Shutdown allows you to set a time for your computer to shut down, which we'll get to in a moment.
3. Shutdown with power outage
sudo shutdown -P now
Or
sudo power off
When your Linux PC or server is in a different room, having to physically press the power button can be a huge hassle. Fortunately, sudo poweroff
Automatically kills all power delivered to your computer so your CPU is safe from power surges and other power-related things that can break it.
However, the best Linux shutdown command to use is the shutdown
with a sign -P
Just remember it needs a capital “P” not a lowercase one.
4. Shut down after X minutes
sudo shutdown +
Suppose you have a process that will finish in 30 minutes. Maybe you're downloading something and you think it will be executed around that time. You can try replacing now
b +
And the amount of time you want to wait in minutes before shutting down. For example: sudo shutdown +30
The computer shuts down after 30 minutes.
Remember that this doesn't wait for any processes to finish before running, so if your task takes a little longer than it should, this Linux shutdown command will shut down your computer once the countdown is over.
5. Closing at a specific time
sudo shutdown :
If you're like me, falling asleep at your keyboard at 3 a.m. and waking up to a warm computer that's been playing music from YouTube all night, you'll wish there was a way to shut it down after a certain time. Fortunately, shutdown lets you choose the time, too.
For example, using sudo shutdown -P 2:45
To shut down your Linux computer once it reaches 2:45 AM. The time is read using 24-hour format, so you will need to type sudo shutdown -P 14:45
If you want to turn it off at 2:45 PM.
6. Send a warning message before shutting down
sudo shutdown " "
When running a Linux server with multiple users connected, it's a good idea to send a message to inform everyone of the shutdown. By adding something between the quotes, the Linux server can send a custom message to other users via the command line.
For automatic shutdown and reboot functions on servers, this message can be really important. You can add this to a script that runs at boot. This way, your Linux server can automatically shut down for maintenance or a scheduled update.
7. Basic reboot command
sudo shutdown -r now
Or
sudo reboot
Using the tag -r
You can restart your computer instead of shutting it down. You can replace now
In time to perform a scheduled shutdown, which works great for automated systems and servers with nightly updates.
Instead, there is an order. sudo reboot
But this command does not allow you to set the time. It works the same way sudo shutdown -r now
For the most part.
Tip: It's a good idea to restart your computer after updating your Linux kernel.
8. Forced closure orders
sudo poweroff -f
Or
sudo halt -f
Or
sudo shutdown -f
It's not every day that you get a system so unresponsive that most commands won't work. Commands can poweroff
و halt
و shutdown
to take knowledge -f
To force shutdown. This is essentially the electronic version of the power switch – it will force-kill all tasks and shut down.
Only use this when normal shutdown and reboot commands don't work. You are bound to lose data (and system integrity) whenever you use this.
Bonus: Cancel Shutdown Order
sudo shutdown -c
Suppose you made a mistake and wanted to cancel an order. shutdown
Scheduled. Pressing will not result in Ctrl + C No writing exit
In the command line to stop it.
Contains command shutdown
On choice -c
Which tells the system to cancel anytime you plan to close it.
Frequently Asked Questions
Q1. Do Linux shutdown commands crash applications?
answer. The shutdown command will not disable applications, but if you have unsaved files, your changes will be lost when you shut down the system.
Q2. Why do I need to type “sudo” every time I enter a shutdown command on Linux?
answer. The shutdown command is a system-level application, which is why it requires superuser privileges to run.
Q3. Can I shut down my computer before the scheduled shutdown?
answer. A scheduled shutdown only occurs when conditions are met. You can safely shut down your computer at any time before the scheduled shutdown.