Now that we have become experts at installing and configuring our Raspberry Pi, we need to see how to properly shut down and reboot a Raspberry Pi.
And it is that a task that seems trivial on any computer, shutting down our Raspberry Pi correctly is of vital importance This gadget doesn’t have a power button!
Under no circumstances should we turn off a Raspberry Pi by unplugging the power cable. Doing so runs a huge risk of corrupting the files on the SD card, which forces us to format it and reinstall from scratch.
In fact, the alarming tendency to corrupt the SD card is one of the biggest problems with the Raspberry Pi. Shutting it down properly helps reduce the chance of a corrupted SD card (although it doesn’t eliminate it completely).
Shut Down Raspberry Pi from Command Line
The correct way to shut down a Raspberry Pi from the command line is to use the command:
sudo shutdown -h now
Where -h corresponds to the halt option and now indicates that we want to start the shutdown at this moment.
If instead of shutting it down we want to schedule the shutdown, we can use:
shutdown hours
Where we must replace hours and minutes with the desired value. If we want to cancel a scheduled shutdown with the previous command, we use:
sudo shutdown -c
There are other similar commands to shut down the Raspberry Pi. This leads to some confusion, so let’s look at them. The first alternative is to use the command:
sudo halt
On the other hand, we have the command:
sudo poweroff
Which performs the same functions as halt, but also shuts down the system, turning off the PSU if the board has ACMI. Since the Raspberry Pi does not have a PSU, in this case it is equivalent to halt.
Historically, these commands (shutdown, halt, and poweroff) had small differences. Although they have softened over time and are not entirely applicable to the Raspberry Pi, they remain in certain systems.
We could summarize that shutdown -h corresponds to a normal shutdown, while halt and poweroff correspond to a more abrupt emergency stop. In general, the behavior regarding process termination and power management is different.
In the case of Raspbian, all three commands should have the same behavior. However, out of habit and concern about these small differences, and because they may not be equivalent in other systems, I personally recommend the shutdown command. It’s better not to pick up bad habits.
Reboot Raspberry Pi
Rebooting the system is just as simple as shutting it down. Again we use the shutdown command but adding the -r parameter, like this:
sudo shutdown -r now
Similar to what we have seen about shutting down the Raspberry Pi, we have another alternative command to reboot it:
sudo reboot
Just as in the previous case, the behavior in Raspbian should be similar to using shutdown -r. But, for the sake of differences and good habits, it is recommended to use the shutdown -r command.
Log Out User
Related to shutting down and rebooting the Raspberry Pi, if we only want to log out the current user, we simply have to use the command:
sudo logout
In the next posts in the Raspberry Pi series, we will continue to delve into the details of Raspbian. See you soon!

