Want to restart an Ubuntu server from the command line?
While there are multiple ways to achieve that, look no further than:
This will instantly start the reboot process for your server. I always use it whenever I have to restart my Ubuntu servers hosted on Linode or CloudOcean.
Let's see things in a bit more detail.
Rebooting Ubuntu from the terminal instantly
The simplest way is to use the reboot command to restart your Ubuntu system from the command line:
Sometimes it gives you one minute of buffer time. But on some systems, it starts the reboot procedure immediately.
If you don't want to worry about that, use the
This is the simplest option that works pretty well with a system on which you are the sole user.
But on a system with other users, using the shutdown will be more appropriate.
Schedule a reboot with shutdown command in Ubuntu
You can also use the shutdown command with option
-r to restart the system.
sudo shutdown -r
This will schedule a shutdown in one minute.
[email protected]:~# shutdown -r Reboot scheduled for Mon 2022-07-25 15:13:31 UTC, use 'shutdown -c' to cancel.
If there are other users logged on to the server, they will receive a message about the scheduled reboot:
Broadcast message from [email protected] on pts/0 (Mon 2022-07-25 15:12:31 UTC): The system is going down for reboot at Mon 2022-07-25 15:13:31 UTC!
You can change the reboot schedule by delaying it for certain minutes to certain hours.
To restart the server automatically after 30 minutes from now, use:
sudo shutdown -r +30
To restart the server automatically at 20:00 hours (in local system time):
sudo shutdown -r 20:00
It will inform you about the scheduled reboot:
[email protected]:~# shutdown -r 20:00 Reboot scheduled for Mon 2022-07-25 20:00:00 UTC, use 'shutdown -c' to cancel.
You can cancel a scheduled reboot or shutdown with the following command:
sudo shutdown -c
Bonus tip: Use systemd command
Considering that Ubuntu uses systemd, you can use the systemctl command to restart your Ubuntu system:
sudo systemctl reboot
I am not a fan of this command. I prefer the reboot or shutdown commands for restarting my Ubuntu servers.