Before you can power off the Raspberry Pi you will have to first shut it down safely. There are two ways to shut down the Raspberry Pi. The first is to use the desktop shutdown button and the second is to enter a command into a terminal window.
To shut down the Raspberry Pi using the desktop simply left click the mouse button on the red power icon at the bottom right hand corner of your desktop.
The next window will display a number of options including rebooting the Raspberry Pi. Click on the shut down button to shutdown the device.
When the Raspberry Pi has shut down the screen will turn black. Wait at least 5 seconds before you power off the Raspberry Pi from the mains.
To shut down the Raspberry Pi from a terminal window you can enter the following commands.
sudo shutdown -h 0
The shutdown command above is used to shutdown the Raspberry Pi followed by the flag ‘-h’. Flags are used to provide additional parameters to commands and in the example above the ‘-h’ is referring to halt. The zero number that follows the flag informs the Raspberry Pi to shut down immediatley.
You can also reboot the Raspberry Pi using the shutdown command. Enter the following into a terminal window.
sudo shutdown -r 0
The ‘-r’ flag indicates that a reboot is to be performed.