Some time ago, seeing that to shut down / restart my previous laptop I had to do several clicks, I created a couple of .desktop files to do it directly from the Ubuntu dock. These shortcuts can come in handy if we want to get to the point, but they can also be dangerous because we can accidentally click on them and lose the work we were doing. That is more difficult if we enter the command manually, something that can be done using the different existing launchers. Whatever the reason we are interested in, in this article we will show you several ways to restart or shut down a computer from the terminal.
Among the options that we will mention below, some seem to be synonymous with the same action, but they are not. To some of them we can add some parameters to, for example, make the computer turn off after a lapse of time. Needless to say, if you're going to test, it's worth testing after you've saved whatever work you're doing or running in a virtual machine.
How to shut down a PC from the terminal
Command power off
The command power off will turn off the equipment as if we had chosen the option to turn off in the exit menu, but without asking. If we don't have anything open, the equipment will shut down almost immediately.
Command shutdown
Similar to the previous one, the command shutdown shut down or restart the PC, but when do we tell him. We can add some options to it, like the -r behind to restart the operating system. As if that were not enough, we can also configure it to turn off / restart after a while or an hour, something we would do using the commands in the following table:
Command | Action |
---|---|
shutdown -r | Restart computer. |
shutdown -r + TimeInMinutes | Restart when the marked time passes. |
shutdown -r TIME | Restart the computer at the time we tell you. |
shutdown TIME | Turn off equipment at the selected time. |
shutdown -c | To cancel an order. |
To set the time, the format is the same as that seen on a clock, that is, 16.00:XNUMX p.m. to XNUMX:XNUMX p.m., with the colon included. Y if we want to avoid warning messages, we will use "sudo" in front of the command.
How to restart a PC from the terminal
Command reboot
The equivalent of power off if we want to restart is reboot. This command will restart the operating system, something he usually does without asking. If the system detects that there is something important running, we will see a warning, but we can avoid it by using sudo in front of the command.
Command init
The command init It will also help us to restart or turn off a PC. The commands would look like this:
Command | Action |
---|---|
init 0 | Turn off the equipment. |
init 6 | Restart. |
init 1 | Enter rescue mode. |
Do you already know how to shut down or restart a PC from the terminal? What is your favorite option?
That is already wanting to complicate your life more. ?
init 0 and shutdown -r do not work for me on debian 10
why will it be? It does not give me a ball, it says invalid command or something
I don't remember well like that