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
The 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
.
reboot [OPTIONS...] [ARG]
Firstly option flags are supplied followed by arguments. Both are optional.
Flags
-p
Switch off the machine-f
Force immediate halt/power-off/reboot-w
Don't halt/power-off/reboot, just write wtmp record-d
Don't write wtmp record
Arguments
--no-wall
Don't send wall message to users before halt/power-off/reboot--reboot
Reboot the machine--halt
Halt the machine
Basic Usage
sudo reboot
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 reboot
.
If for some reason the system refuses to restart try forcing it to by using the -f
flag.
sudo reboot -f
Shutdown Command
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 +0
or 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
Using Systemctl
You can also perform a restart using systemctl
.
sudo systemctl reboot
By default systemctl
will notify all logged-in users about the impending restart. If you don't want to display a message pass in the --no-wall
argument.
sudo systemctl --no-wall reboot
Conclusion
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.