Understanding the reboot command on Linux

Shutting down your PC can be as simple as pressing the power button on your PC or laptop, or by just clicking the Shutdown option in your operating system. However, on Linux, there are several ways through which you can shut down and restart or reboot your PC from the Terminal. These methods can be helpful to you, specially if you are trying to troubleshoot any problem while your system reboots or shuts down.

And in this article, we will take a detailed look at the reboot command and understand its flags so that you can take advantage of the command line interface while troubleshooting your PC or a remote server so that you don’t have to rely on the different Graphical Desktop Environments across different Linux distributions.

Using the Reboot command on Linux

On any Linux distribution, just open a Terminal window and type the reboot command without any flags:

reboot
Running The Reboot Command Will Restart Your PC
Running The Reboot Command Will Restart Your PC

Now, this command will begin a graceful shutdown process which will close all the running programs and services first and then restart your computer or laptop. But if you need your system to be shutdown immediately without having to worry about the running applications or services, then you can use the -force flag with admin privileges like this:

sudo reboot -f

Do not use this command every time because applications and the processes most definitely need a proper process to shut down before the whole operating system gets rebooted. If you just want to power off your system, then you can also use the reboot command along with the –poweroff flag like this:

reboot --poweroff

Similarly, you can shut down your PC forcefully with the -f flag with the reboot command like this:

sudo reboot --poweroff -f
You Can Also Forcefully Shutdown Your PC If You Need To
You Can Also Forcefully Shutdown Your PC If You Need To

And as mentioned earlier, this command will forcefully shut down your system without giving time to the processes and applications to properly close. If you just want to shut down your PC, then you should rather use the halt option.

reboot -h

This command will stop the running services and programs gracefully on your PC and then brings the system to a complete halt before shutting down. This can be compared to the normal shut down process when you do it from the super menu on your Linux Desktop. Obviously, this should be used instead of the -f flag.

Using the halt option, what your system is also doing is that it records the shut-down process in the wtmp file, which keeps track of your login time, rebooting time etc. And if you don’t want the event recorded on your PC, then you can use the -n flag or the -no-wtmp command option along with the reboot command.

reboot -h -n

The WTMP file is located in /var/log/wtmp and can be read using the last command.

Reading The WTMP File Using Last Command
Reading The WTMP File Using Last Command
sudo last /var/log/wtmp

Wrapping Up

Well, that’s pretty much all you need to know about the reboot command on Linux based operating systems. You can always use the GUI method to shut down and restart your PC, but it is always good to know the command line method of doing the same thing. If you lose the GUI desktop environment by accident or log in to a remote server which only has the command line, and you would have to interact with it, then you should know a few basic commands and its sub-commands.

Also Read

Understanding the file command on Linux

Understanding the Terminal Aliases on Linux distributions

References

The Manual of Reboot command on Linux