5 Ways to Turn Off Linux Via Terminal
5 Ways to Turn Off Linux Via Terminal
Shutting down Linux via terminal is often necessary for a number of reasons, for example because you want to keep things simpler or when you are connected via SSH to a remote computer or server and want to restart or completely shut-down it.
But how can you do this? Several linux commands are available for you to shut down or restart (or reboot) your Linux computer via the command line.
1.Shutdown
If you are finished using your Linux, the solution to shutting it down is to use the shutdown instruction. This can be used to permanently shutdown the computer (until you decide to reboot the computer) or restart it. The syntax for this command is:
shutdown [options] [time] [message]
For example, to shut down the computer immediately, you can use the command:
shutdown -h now
Here, -h means stop while now obviously means that the instruction should be executed immediately. Different delays can be used. For example, you might use +5 instead, which will tell the computer to carry out the shutdown procedure in five minutes.
If you want to enter a message, it will be shown to all logged in users:
shutdown -h +5 "Server is shutdown, please save your work and logout."
Note that you can find a complete list of switches for this command by entering:
[command] --help
Shutdown help
An alternative option is to use the -r command to restart the computer. This is used instead of -h , so to restart your computer or server, you can use:
shutdown -r +5 "Server restarts in five minutes, please save your work and logout"
Any scheduled shutdown or restart can be canceled by entering the -c cancel command:
shutdown -c
2. Reboot
The next command to turn off Linux via the terminal is to use the reboot command.
The standard reboot command is:
reboot
This will prompt your computer to turn itself off, and then back on. However, if you want to power off the device then the -p switch will work:
reboot -p
Another option is to force a reboot. This can be useful if an app or service is hanging and you need a quick restart:
reboot -f
This forcibly reboots your Linux.
3. Halt
We've looked at the -h switch above, but halt can be used as a standalone command. This will cause the computer to shut down immediately, by using a simple command:
halt
The -f switch can also be used with halt, but the results are inconsistent, and can cause system stability issues.
4. Power off
You may prefer the term poweroff command. It's not exactly the same as halt. As well as using -f to force poweroff, you can also use -w to log system reboot calls to /var/log/wtmp . It is a useful debugging tool, like –vote , which can help with shutdown issues.
poweroff --verbose
5. Emergency Option: REISUB
All the above commands can be used in situations when the system is running without problems. But what if it crashes? What if the PC or server is hanging, and can't be rebooted in a fun way?
The answer then is a keyboard combination. If you have switched from Windows, you may know that Ctrl + Alt + Del brings up a menu with Shutdown as an option. If it is held longer, the machine will automatically shut down. Whereas on a Mac, you can simply hold down the power button (an option that also works on Windows hardware).
On Linux, the keyboard combination is Alt + Print Screen + B to reboot. However, if this doesn't work, or there is a more complex issue, you can change the combination, using up to six buttons. This is known as REISUB.
* unRaw – Takes keyboard control back from the X display server.
* tErminate – Sends a SIGTERM termination signal to all processes, to terminate.
* kIll – As above, but the SIGKILL signal, which forces an immediate termination to the process.
* Sync – Flushes data to disk.
* Unmount – This changes all filesystems to a read-only state.
* reBoot – Restart your system.
To make this work, you have to hold down Alt + Print Screen , then the REISUB key in that order. Allow a second or two between each key press. Note that this method usually doesn't work on machines with ARM architecture like Raspberry Pi.
Conclusion
These five ways to shut down Linux via the terminal are very useful because they can be used on the computer itself, or via remote SSH. Because this command is so concise, it gets used quickly.
Post a Comment