When you’re in the same room as a server, shutting it down or rebooting it is simple. You could hold the power button or even unplug the whole machine. Not only are these solutions inelegant, they have the potential to corrupt your data and potentially damage your hardware! They also don’t work when you’re logged into your favorite remote server.
Depending on your hosting provider, you very well may have a nice GUI interface at your disposal, completely with a shiny red button to shutdown or reboot the machine. It’s a sufficient solution, but doesn’t necessarily scale across different hosting providers.
Knowing how to do things on the command-line allows you to be as stack agnostic as possible. You can switch easily between hosting providers and always have the same consistent set of tools at your disposal. This flexibility comes in extra handy when you’re working with a brand new stack that you’re not familiar with.
🐊 Alligator.io recommends ⤵⚛️ Fullstack Advanced React & GraphQL by Wes Bos
The commands discussed in this article,
reboot do exactly as their names imply. They will shut down or reboot your machine. Because these are somewhat destructive commands, if you run them locally, be ready for your system to system to shut down or reboot.
Using a remote development or staging server running a Unix-like operating system (like Linux) would be an ideal scenario. Because you will in fact take your server off line with these commands, I wouldn’t recommend running them on a production server unless you really want to reboot the box.
The following commands will more than likely require elevated super-user privileges to run. If you receive an error about a command not being found, just try it again with
If you don’t have super-user privilege on the machine you’re on, you more than likely won’t be able to shut it down or reboot it.
Shutting down a system can be done with the
shutdown command, in it’s simplest form, without any arguments:
$ shutdown # Graceful shutdown in 1 minute
Without any arguments, the
shutdown command will schedule the shutdown for a minute out from the current time. Because it’s scheduled in the future, you have a window of opportunity to cancel the shutdown by way of the
$ shutdown -c # Cancel a scheduled shutdown
You may have noticed that a broadcast message was issued when you ran the first
shutdown command. That’s the wall message, and it’s issued to all of the users that are currently logged into the system.
The time of the shutdown can be scheduled, as well as the content of the wall message that is presented to your users:
$ shutdown now "Cya later alligator" # Immediately shut down $ shutdown +5 "Cya later alligator" # Shutdown in 5 minutes
Because the arguments are passed in order and without additional
--flags to indicate what the values are, they must be passed in a specific order. That means you can’t customize the wall message without also specifying a time.
If you are just looking for a quick and easy way to reboot a server, the
reboot command is about as easy as it comes:
$ reboot # Graceful restart $ reboot -f # Forceful, like holding the power button
In tune with the Unix Philosophy, the
reboot command does what it’s name implies and not much else.
shutdown command on the other hand, actually does a bit more than the “shutdown” name infers, by allowing you to use it to reboot a machine as well as shut it down.
Why this is important is that while the
reboot command is quick and gets the job done, using the
shutdown command to restart your machine gives you the added benefit of being able to schedule things as well as edit the wall message.
To tell the
shutdown command to reboot instead of just shutting down, pass in the
--reboot argument, along with any other options:
$ shutdown --reboot # Reboot in 1 minute $ shutdown -r now "After while crocodile" # Immediately reboot $ shutdown -r +5 "After while crocodile" # Reboot in 5 minutes
Similar to how we canceled a full shutdown earlier, another added benefit over
reboot is that you can also cancel a reboot via
shutdown by calling it again with the
$ shutdown -c # Cancel a scheduled shutdown (or reboot!)