How to Restart Linux/Ubuntu Server with Command Line
There are many reasons for restarting your Linux/Ubuntu server, whether that is due to newly installed software that requires it or a program that has crashed.
In this guide, we will go through some different ways to restart your server using the command-line. We will also look at how to change the behaviour of those commands.
Before you begin you must be able to run commands in
sudo mode or your user account must have root privileges.
reboot command is the easiest way to restart a Linux server due to its simplicity. You can also add optional flags to change the action of the command; let's have a look at the syntax of
reboot [OPTIONS...] [ARG]
Firstly option flags are supplied followed by arguments. Both are optional.
-pSwitch off the machine
-fForce immediate halt/power-off/reboot
-wDon't halt/power-off/reboot, just write wtmp record
-dDon't write wtmp record
--no-wallDon't send wall message to users before halt/power-off/reboot
--rebootReboot the machine
--haltHalt the machine
The default behaviour of reboot is to restart the machine immediately, stopping any processes that might be running. In most cases, the above is how you will use
If for some reason the system refuses to restart try forcing it to by using the
sudo reboot -f
As the name suggests the
shutdown command is primarily for powering-off the system, though by using an option flag it can perform reboots. Let's have a look at the shutdown syntax:
shutdown [OPTIONS...] [TIME] [WALL...]
shutdown has more functionality than the reboot command, as on top of option flags one can set a specific time to shut down and a custom wall message to warn all logged-in users.
Restart the System Using Shutdown
sudo shutdown -r
The default behaviour of shutdown is to wait 1 minute to reboot. If you want an immediate restart pass in
now as the second option (time).
sudo shutdown -r now
Restart the system in 1 hour:
sudo shutdown -r +60
You can also set a restart at a specific time of the day and give a message to all logged-in users.
sudo shutdown -r 12:00 "System restarting at noon GMT due to software upgrade."
Cancel a Reboot
To cancel a reboot using the shutdown command pass in the -c flag.
sudo shutdown -c
You can also perform a restart using
sudo systemctl reboot
systemctl will notify all logged-in users about the impending restart. If you don't want to display a message pass in the
sudo systemctl --no-wall reboot
You now know a number of different ways to restart your Linux/Ubuntu including set the time for execution and notifying users with custom messages.