
Do you feel like starting over? This tutorial will show you how to cleanly and safely restart or shutdown your Linux or macOS computer from the command line.
We go down
Sometimes you just have to restart or shut down completely. If you are working on a server without a GUI or you are in an SSH session on a remote computer, command line is your only option. Linux and Unix-like systems, like macOS, provide various commands to shutdown or reboot your system directly from the command line.
The commands you can use are:
- delete
- restart
- stop
- off
Looking for these commands in man pages can be confusing. Depending on the command line alternatives you choose, all these commands can perform closures, it restarts and the system stops. Actually, the man pages of reboot
, halt
, and poweroff
Contains exactly the same information.
What's behind this?
The solution is in the system ear system that replaced the venerable System V init
system. In the world of Linux, Fedora started using systemd
on 2011. Since then it has been adopted by a large number of distributions. Debian and Ubuntu swapped to systemd
on 2015.
Upon systemd
distributions supported by shutdown
, reboot
, halt
, and poweroff
The commands are effectively shortcuts that point to the systemctl
command. Keeping these commands provides a degree of compatibility with System V init
Distributions supported by means that shell scripts (and System V hard core system administrators) do not collapse if moved to a computer with a systemd
distribution running on it.
Usando Shutdown
Shutting down or rebooting a multi-user system means you need to plan ahead. You must choose when it will shut down or restart, and warn other system users that shutdown is coming and when. If it is your own computer and you are the only one who uses it, life is much simpler.
To run any of these commands, must be in the sudo
group. In other words, you must have superuser permissions and be able to use the sudo
command. Whether the command you have issued will take effect immediately and will not affect other logged in users, you will not need to use sudo
. If you try to use one of these commands and the command is rejected, try again with sudo
.
By default the shutdown
The command ensures that all processes are stopped cleanly, all file systems are in sync and all CPU activity has ceased. This is the state of “alto”. Then send a message to the hardware to cut the power. It is, in any case, is the off state or “off”.
It is common to pass shutdown
some parameters, as a timestring and a message to be sent to registered users to warn them of the closure. Let's schedule a shutdown for 15 minutes from now on. Writes shutdown
, a space, +15
, a space and later the message to send to users.
shutdown +15 Shutting down in 15 minutes!
The time chain we used was +15
, what represents 15 minutes from now on. the +
it's optional. We could have written 15
.
We receive a response confirming that a shutdown is scheduled and when it will occur. Users who have logged in will receive the message we provide them.
To cancel a shutdown, use el -c
(cancel) option.
shutdown -c
Even if you don't receive any notification that your closure has been canceled, logged in users do receive a notification.
If you don't provide a timestring, a shutdown will be scheduled for one minute from now on. Note that you cannot send a message to logged in users if you do not specify a timestring.
shutdown
If you can't wait a minute, you can use now
as the time chain and shutdown takes righ now effect. Using now
is how to use +0
.
The time string can be a set time, like the 23:00. You must follow the format of HH:MM
and it should be on the clock 24 hours. Five minutes before the system stops working, new logins are avoided.
We know the default action of shutdown
causes the computer to go to a stopped state and then to a shutdown state. We can override this behavior by passing it other command line options.
- the
-H
The option (stop) will make your computer shut down, but it won't ask the hardware to shut down. - the
-P
(off) is the default action. The computer goes to the stop state and then shuts down. - the
-r
The option (restart) will bring your computer to stop state and then restart it. - the
-h
The option (stop and turn off) is the same as-P
. If you use-h
and-H
together, the-H
option takes precedence. - the
-c
The option (cancel) will cancel any shutdown, scheduled stop or restart.
Here is an example where we have scheduled a reboot.
shutdown -r 08:20 System rebooting at 08:20
The reboot commands, stop and turn off
These commands perform the action suggested by their name. Despite this, each of them will accept command line options for any of them to perform a reboot, a stop or a shutdown. But, Why confuse things? These commands are best used verbatim.
If you want to restart now, use reboot
. If you want to turn off now, use poweroff
and if you want to stop the system now, use halt
.
reboot
halt
poweroff
These commands have immediate effect. If any of these commands are rejected, precede them with sudo
. But note that, in general, a negative is because there are other users connected to the system that is about to disconnect.
Which command is right for me?
In multi-user environments using shutdown
performing these actions gives you more control. The ease of scheduling outages and restarts, and to alert users with a broadcast message will be invaluable in these cases. For a single user computer, reboot
and poweroff
will probably meet your needs.
setTimeout(function(){
!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
if(!f._fbq)f._fbq = n;n.push=n;n.loaded=!0;n.version=’2.0′;
n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s) } (window, document,’script’,
‘https://connect.facebook.net/en_US/fbevents.js’);
fbq(‘init’, ‘335401813750447’);
fbq(‘track’, ‘PageView’);
},3000);