Raspberry pi restart command

How to safely shutdown or reboot your raspberry pi

How to safely shutdown or reboot your raspberry pi (Debian/Raspbian)

Of course, we all know you can shut down any computer by pulling the plug or switching off the switch. Most PCs can be forcibly switched off – even when they’ve crashed – by holding the power button down for 3 seconds. But we also know, or should know, that doing this isn’t good for the computer. For desktops and laptops, it can cause problems on the hard disk drive. For the Raspberry Pi, it can cause problems on your SD card. In fact it can corrupt your SD card so that you have to re-image it. Not a huge deal, unless you’ve just done a long compile and not yet backed up the files. :cry:

In the short month I’ve been ‘Pi’ing, I’ve only had one card need re-imaging (running an early version of OpenELEC). I don’t think it was down to an “unofficial hard reboot”* though because I don’t generally do them. I found out very early on how to shut down the Pi properly. You can do this, even when it’s crashed or frozen, as long as you have…

  1. ssh enabled, and
  2. access to another computer on the same network (you can even use your smartphone.)

But before we go into that, let’s talk about how to shut down the proper way when your system isn’t frozen.

So. What is the best way to shut down before you power off the Raspberry Pi?

sudo shutdown -h now (or sudo halt )

You can’t use shutdown (or halt ) unless you have sudo privileges.

-h means halt the system
now means do it straight away. You could also add number 10 to tell it to shut down in 10 minutes. You can even give a specific time 19:45 (in 24 hour format with a : colon).

sudo shutdown -h now

Notice that when you give the shutdown command it sends out a message to all logged in users
“The system is going down for system halt NOW!”

If you are working directly on the Pi, within a few seconds you should get a message that the system has halted. If you are logged in through ssh, you’ll find that your console window will close.

If you merely want to reboot

To reboot, you can change the -h for -r like this…

sudo shutdown -r now (or sudo reboot )

sudo shutdown -r now

This time the message is…
“The system is going down for reboot NOW!”

So what if the system’s frozen?

That’s when ssh comes in handy. Use an ssh client program on another computer connected to the same network. Start an Xterm console window and use the above commands…

sudo shutdown -h now (or sudo halt ) OR
sudo shutdown -r now (or sudo reboot )

…but be aware that when the system goes down or reboots, your ssh session will end (obviously, you can’t be connected to a machine which is shut down).

Good ssh clients are tunnelier and Putty (Open Source – Windows/Linux)

I may go into how to use ssh in another post when I get time :-D

* “unofficial hard reboot” = pulling the plug

44 Responses to “How to safely shutdown or reboot your raspberry pi”

You can also use the shorthands `halt` and `reboot`.


How To Restart Raspberry Pi Safely And Quickly

To avoid damaging the file system on the SD card, you should always shut down and reboot the Raspberry Pi properly (not just unplug the power cord).

To safely shut down or reboot your Raspberry Pi through the GUI, simply find the appropriate buttons in the menu.

In this post, I will show you how to restart raspberry pi from the command line (or you can see video lessons)

How To Find IP Address Of Raspberry Pi

Guys & girls, there is nothing easier than finding an IP address of your little computer! Let me quickly describe one…

When RPi (or any other UNIX-like system) shuts down or reboots correctly, using commands from the terminal or their GUI equivalents, it first tries to shut down all gracefully processes by sending them a SIGTERM signal, which notifies them to save data and shut down. After a while, to all remaining processes, it sends SIGKILL, unmounts all file systems and sends the appropriate command to the ACPI power management interface.

When RPi (or any other UNIX-like system) shuts down or reboots correctly, using commands from the terminal or their GUI equivalents, it first tries to shut down all gracefully processes by sending them a SIGTERM signal, which notifies them to save data and shut down. After a while, to all remaining processes, it sends SIGKILL, unmounts all file systems, and sends the appropriate command to the ACPI power management interface. This is done by invoking the shutdown(8) program.

What if, instead of shutting down gracefully after sending SIGTERM, we tell our RPi to just reboot? And what happens if we do this without hitting control-alt-delete first. We might find that a few processes still hang around, or nothing seems to happen at all, or that a few files have been corrupted! This is because the usual shutdown sequence has not happened and so some services don’t stop in time and leave locks on disk which other services can’t see when you reboot. In addition file system integrity cannot be guaranteed when booting in this way, unless you add it explicitly as an option to your /etc/fstab for instance.

The latter is a good idea for systems that aren’t expected to be turned off regularly.

The solution? Well, we could use a system that can recognize when it is shutting down or rebooting and then do the right thing, but there are already some tools out there that will do this for us if we give them the chance. They are called Init Replacement distributions.

One method acts as an intermediary between the kernel’s power management functions and the other services on the system — It receives commands from userspace telling it to shut down or reboot, waits until no processes are using files anymore (e.g.: no open file descriptors) before unmapping all memory mappings of processes, sends a SIGTERM to all processes and only after they have shut down, tells the kernel to reboot or shutdown. This method ensures that processes have time to clean up so you can be more confident that the machine will boot again successfully following an ungraceful shutdown, but it has drawbacks — if any process is using files when you attempt to shut down the system (e.g.: open sockets in services like httpd), then you may get lockups or corruptions.

Turn off the Raspberry Pi

Use any of the above commands to turn off the RPi correctly:

Once the shutdown process is complete, the green LED on the Raspberry Pi board will blink a few times — it is then safe to disconnect the power cable.

It’s okay if only the red LED stays on — it means that the Raspberry Pi is connected to a stable power source.

Safely reboot Raspberry Pi

Execute any of the following commands to safely reboot the RPi:

But if you can’t wait to see what happens when you power up the device again, here’s an interesting experiment.

First, make sure you have a good power supply and connect everything as explained in the Quick Start Guide. Now boot your Raspberry Pi for about 10 seconds just long enough to log onto the screen. Once you’re on type this command sudo shutdown -r now. You’ll see the light on the Pi starts to flicker as it reboots, but this time instead of turning it off it will restart again and again.

What’s happening is almost certainly a hardware problem. The Broadcom system on chip (SoC) device contains several “cores” that communicate with each other via an internal memory bus. This is not to be confused with the main system memory, which can also be accessed by the cores, and in fact, it’s through here that the Linux kernel starts its initial boot process.

That memory access has gone wrong and as a result, the kernel is unable to start properly. Under normal circumstances, that error would be detected by the OS and it would shut itself down so as not to cause further damage. However, in this case, because there’s no OS loaded it doesn’t know what to do next so the only option is to keep rebooting.

How do I restart my Raspberry Pi from a remote system?

Something like this might help:

this command connects to your Raspberry using SSH and issues a restart command, make sure you replace 192.168.1.XXX with the real address.

Have fun guys & girls!

You might also want to know other tricks with RPi:


28 Raspberry Pi Linux Commands: A Quick Guide to Use the Command Line for Raspberry Pi


When you get your hands on a Raspberry Pi for the very first time, you need to install an operating system with a Micro-SD card connected to it. Raspberry Pi not only supports their official Raspberry Pi OS on the Raspberry Pi but also various other flavors of Linux distributions. So once you install an operating system on a Raspberry Pi, there are different ways of interacting with it.

  • Connecting a display through the HDMI connector to experience a user interface
  • Communicate through the serial interface
  • Communicate via an SSH connection remotely

When you connect to a display, you are presented with a user interface and it is easy to navigate around the operating system just like your personal computers. But when you make a connection through serial interface or remote SSH, you don’t have a user interface as such. But instead, you will have to navigate around your Raspberry Pi via a command-line which is similar to the command prompt or PowerShell in a windows PC and terminal on a Macintosh.

Using a command-line you normally instruct the Raspberry Pi to perform tasks by entering commands via your keyboard, which is different from the traditional way of interaction, which is using a mouse. You might think that it is much easier to connect a display and use a user interface to interact with a Raspberry Pi, but however, once you get familiar with the command-line, your workflow is going to be much faster and also you will have more control over your Raspberry Pi. You will be able to combine these commands together into scripts and run them to complete tasks more efficiently. Also, there could be projects where you need to deploy your Raspberry Pi in a different location and in this situation, command line is going to be very useful.

This blog will help you get familiar with most of the useful commands that you will need in need to navigate through your Raspberry Pi and interact with it! Also, these commands will work with any Linux distribution on the Raspberry Pi and even any other systems running Linux!

Command-Line on the Raspberry Pi

Once you log in to the command-line on your Raspberry Pi, the first line will start with the prompt [email protected] $. This indicates that you have successfully logged in to your Raspberry Pi. You can enter your commands in the commands line in front of this text.

Updating the system

Once you turn on your Raspberry Pi, it’s good practice to start off by updating your Raspberry Pi Operating System and it’s sources to the latest version. You can type the following commands to do so.

  • sudo apt-get update
  • sudo apt-get upgrade
  • sudo apt-get dist-upgrade
  • sudo rpi-update

These commands can be entered one by one or they can also be combined as follows

sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade && sudo rpi-update

Note: You enter “sudo” at the beginning to tell the Raspberry Pi that you are entering the commands as a “root” user. This allows you to enter all the commands that are available within Linux without any restrictions.

There are a few commands that you can use in order to navigate through your files and folders.

pwd : stands for print working directory and it shows you in which directory you are at

ls : it will list all contents of the directory you are at

ls -l : it will list all the contents of the directory you are at and show more details regarding the files

cd : it is used alone to come back to the root directory. However, if you use “cd” in combination with a name of another folder in the current directory, it will switch you to that directory.

Example: cd pifiles will switch you to a directory called “pifiles”.

cd.. : it is used to move back from one directory to another

Perform file and folder operations

There are commands that you can use to perform functions such as making new folders, copying/moving/deleting files, and folders.

mkdir: it will create a new directory

Example: mkdir pidir will create a new directory, where “pidir” is the label of the directory.

cp: this will help you to copy files from one directory to another

Example: cp /home/pi/new/file.txt /home/pi/project/ will copy the file.txt from /home/pi/new/ directory and paste in to /home/pi/project/ directory.

mv: this will act as a cut and paste command where the file will be moved from one directory to another. However, this command can be used to rename file names that are in the same directory.

Example: mv /home/pi/new/file.txt /home/pi/project/ will move the file.txt from /home/pi/new/ directory to /home/pi/project/ directory.

Example: mv oldproject.txt newproject.txt will change the file name from oldproject to newproject

rm: this will be useful to delete files that you no longer need anymore

Example: rm testfile.txt will delete the testfile.txt from its directory

clear: this will clear up all the commands in the current screen and display a clean new screen.

Creating a new file and editing the content

Once you create a file such as a text file, you might want to edit the contents inside this text file. For this, you might want to use a command-line text editor such as GNU Nano. By entering the command below you will be able to create a new file called newproject.txt or edit an existing file names newproject.txt and will be presented with a space to add content inside this file.

nano newproject.txt

You can create or edit other types of files in the same way by just changing the file format such as newproject.py for python files and newproject.conf for configuration files

Once you create the newproject.txt text file, you will be able to navigate around the document using arrow keys and type content inside the document. Once you are done Press Ctrl+x on your keyboard and then press Y when it asks you whether to save it.

Raspberry Pi hardware information

Sometimes you might want to check the hardware information on your Raspberry Pi and will be lost how to do so. Don’t worry. You can use the commands below to check all the hardware information.

cat /proc/cpuinfo : displays the processor information

cat /proc/meminfo : displays the Raspberry Pi memory informaton

cat /proc/partitions : displays the size and number of partitions on your SD card

cat /proc/version : displays which version of the Pi you are using

vcgencmd measure_temp : shows the CPU temperature and it is important to check this if you are running heavy applications and want to monitor the temperature

free -o -h : this will display the available system memory.

top d1 : This checks the CPU load and displays details for all cores.

df -h : this can be useful to check the amount of free disk space on your Raspberry Pi.

uptime : this displays the how long the Raspberry Pi was running and it’s load average.

Troubleshoot Raspberry Pi hardware

If you are looking for report on how the CPU and RAM on the Raspberry Pi are being taken up by the running processes, you can enter the following command


This will be useful to check whether a particular app is running and also find out whether which apps are slowly down your Raspberry Pi. You can press ctrl+c to exit from this window.

Also, if you are having issues with your network, enter the following command to list about the networks that you are connected to.


If you are connected via Ethernet, check for eth0 section and if you are connected via Wi-Fi, check for wlan0 section. Also, you can have a look at your IP address.

Shutdown and restart your Raspberry Pi

There are a couple of commands that you can use to instantly shutdown or restart your Raspberry Pi

sudo shutdown -h now : This will immediately shut down your Raspberry Pi.

However, if you want a schedules shutdown in 2 hours for example, you should enter the command as follows sudo shutdown -02:00

sudo reboot : This will immediately restart your Raspberry Pi


We hope after following the above commands, you will get more comfortable using the command-line to interact with your Raspberry Pi.