Raspberry Pi Terminal Commands: A Quick Guide for Raspberry Pi Users
Whatsapp Pinterest
Advertisement

Got hold of a Raspberry Pi but not entirely confident with Linux? While the main desktop is easy enough to use, at times you’ll need to rely on command line entry in the terminal. But if you’re new to the Raspbian operating system and Linux, this is easier said than done.

If you’re using a Raspberry Pi computer for a weekend project (perhaps a media center or a home server), then there is a good chance these useful Raspberry Pi command line instructions will save you some time.

Raspberry Pi Commands: You’re Using Linux

You’ve imaged your SD card and booted your Raspberry Pi, and running the Raspbian operating system, updated and configured to optimize your Raspberry Pi.

What you may not have realized is that despite the Windows-style icon-driven desktop, Raspbian is a Linux distribution. Several operating systems are available for Raspberry Pi 11 Operating Systems Your Raspberry Pi Can Run 11 Operating Systems Your Raspberry Pi Can Run The Raspberry Pi's hardware is only one side of the coin. Here are some different Raspberry Pi operating systems you can install. Read More , the vast majority of which are Linux.

This isn’t an attempt to get people using Linux by stealth! You can install Linux on a huge range if devices. Rather, the Raspberry Pi Foundation relies on Linux operating systems because of their open source origins and versatility. While you can use a Linux operating system without using the command line, this is where the real power lies.

Want total control over your Raspbian-powered Raspberry Pi? Begin by launching LX Terminal or booting to the command line.

5 Important Raspberry Pi Update Commands

We wouldn’t expect you to start using the command line without knowing how it works. Essentially, it is a method for instructing the computer to perform tasks, but without a mouse.

Look for the pi@raspberrypi $ prompt when you log in to the terminal. You can enter commands whenever this is displayed.

Probably the first thing you should learn to do from the command line is update your Raspberry Pi. If you’re using Raspbian, this is a case of using three or four commands, to update and upgrade the Pi’s sources and operating system:

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

To save time, combine these into a single chained command:

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

5 Raspberry Pi Command Line Basics

With a mouse-driven GUI, you can easily switch directories and read their contents. However, you may prefer the flexibility of text-based commands.

  • pwd shows you the current directory (print working directory).
  • ls will list the contents of the directory.
  • cd is used to change the directory. For example, cd edward with switch you to a child directory called “Edward” while cd.. returns focus to the parent directory.
  • mkdir newdir will create a new directory, where “newdir” is the directory label. You can also create a succession of new directories with mkdir -p /home/edward/newdir1/newdir2, where both newdir1 and newdir2 are created, but this will only work with the -p
  • clear presents a clean new screen, useful if your previous commands are cluttering things up.

You’ll easily pick up these command line basics. It’s useful to be able to navigate via the command line as some files and folders are invisible to the mouse-driven file manager.

10 Commands for Raspberry Pi Hardware Info

On a Windows PC or Mac you can easily find hardware information by looking in System Information or About This Mac. To find out about your Raspberry Pi’s hardware What Is a Raspberry Pi, and What Can You Do With One? What Is a Raspberry Pi, and What Can You Do With One? What is a Raspberry Pi, who can use one, and why are they so popular? Find out everything you need to know in this week's podcast. Read More , enter the following:

  • cat /proc/cpuinfo

Discover information about the Raspberry Pi's CPU

This will output information about the device’s processor. For instance, where you see “BCM2708”, this indicates that Broadcom manufactured the chip.

Run these proc directory commands to uncover other hardware information.

  • cat /proc/meminfo displays details about the Raspberry Pi’s memory.
  • cat /proc/partitions reveals the size and number of partitions on your SD card or HDD.
  • cat /proc/version shows you which version of the Pi you are using.

Check the current Linux versions

Use these commands to assess what your Raspberry Pi might be capable of. It doesn’t end there. Find further information using the vcgencmd series of commands:

  • vcgencmd measure_temp reveals the CPU temperature (vital if you’re concerned about airflow).
  • vcgencmd get_mem arm && vcgencmd get_mem gpu will reveal the memory split between the CPU and GPU, which can be adjusted in the config screen.
  • free -o -h will display the available system memory.
  • top d1 checks the load on your CPU, displaying details for all cores.
  • df -h is a great way to quickly check the free disk space on your Raspberry Pi.

How much free space does your Raspberry Pi's SD card have?

  • uptime is a simple command that displays the Raspberry Pi’s load average.

3 Commands to Check Connected Devices

Just as you can list the contents of a directory with a single command, Linux lets you list devices connected to your computer.

  • ls /dev/sda* displays a list of partitions on the SD card. For a Raspberry Pi with a HDD attached, substitute sda* with hda*.
  • lsusb displays all attached USB devices. This is crucial for connecting a hard disk drive or other USB hardware that requires configuration.

Use lsusb to learn about USB devices connected to the Raspberry Pi

If the item is listed here, you should be able to set it up.

  • lsblk is another list command you can use. This displays information about all attached block devices (storage that reads and writes in blocks).

3 Commands to Shutdown and Restart Raspberry Pi

Perhaps the most important command line instruction is sudo. This single word instructs Linux-based systems that the following command is to be carried out with “super user” privilege. This is an advanced level of access like (but not the same as) administrator on Windows computers.

Raspberry Pi configuration tool

One of the most common commands for Raspbian users is sudo raspi-config. This opens the configuration screen for the operating system (there is also a desktop version found via main menu). The following three commands may prove useful:

  • startx will start the Raspberry Pi GUI (graphic user environment) and return you to the default Raspbian desktop.
  • sudo shutdown -h now will commence the shutdown process with immediate effect. Schedule a timed shutdown with the format: sudo shutdown -h 21:55
  • sudo reboot is for restarting the Raspberry Pi from the command line.

Raspberry Pi Terminal Commands Are Power

For many people, command line access on any platform is intimidating.

The useful commands listed here are an attempt to give the Raspberry Pi newcomer the bare minimum to get started with the terminal, a small stepping stone to success with whichever Pi project they decide to start.

There’s an added bonus: learning these commands can set you on the road to using Linux, as the majority will work on any distribution! If you’re new to the Raspberry Pi, check out our article on Raspberry Pi basics everyone should know.

And for a cool project, check out how to turn your Raspberry Pi into a secure travel router How to Turn a Raspberry Pi Into a VPN-Secured Travel Router How to Turn a Raspberry Pi Into a VPN-Secured Travel Router Want to secure your internet connection when traveling? Here's how to build a portable VPN router with a Raspberry Pi and OpenWRT. Read More .

Explore more about: Linux Commands, Raspberry Pi, Raspbian, Terminal.

Enjoyed this article? Stay informed by joining our newsletter!

Enter your Email

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Dan
    February 15, 2019 at 8:00 am

    How do I put multiple buttons on a RPI? A stupid question from a newbie here.

  2. Siddhi
    January 19, 2018 at 6:20 pm

    try: ls -a in /Home, open the bash file with 'nano .bashrc' you can then speed up file navigation etc by entering an alias such as "alias multiT='clear; whomami; ls -al'" etc

  3. sir isley reale
    October 6, 2017 at 5:55 pm

    I am on a pi :p

  4. Farjad
    July 13, 2017 at 7:35 am

    Thanks, I recently bought a RPi3, this article proved to be helpful.

  5. Paul
    March 3, 2017 at 12:41 am

    Great article, I've been using bash not just on the Pi, but other architecture as well for a couple of years.

    I always used shutdown to halt or restart from terminal, however I have recently just used poweroff or reboot.

    • Christian Cawley
      March 31, 2017 at 7:38 pm

      Thanks, Paul, nice to hear. Which command do you prefer for shutting down?

  6. mars
    September 2, 2016 at 10:34 pm

    Any command to shutdown and restart in 5 minutes?

    • I eat Pi for tea
      September 21, 2016 at 7:34 am

      shutdown -r 5

  7. Camille
    May 13, 2016 at 11:08 pm

    top d 1 for checking cpu usage for instance
    df -h for disk space
    uptime for load average for instance

  8. Christopher
    May 11, 2016 at 2:27 am

    cat /proc/version does not really give you useful information, unless you are a supergeek hacker. It doesn't really tell you the version of Raspberry Pi you have. Rather it tells you what version of Linux kernel you are running, plus a few other geekish things.

    The following command will update your Raspberry Pi thoroughly!
    Type it in once (or copy and paste it). Once it is in the command history, it is super easy to use. All you have to do is use the up arrow key to find it, hit Enter, and off you go again.
    I use this command almost every day.

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

  9. Giovanni
    April 14, 2014 at 8:05 am

    Nice article, and you're right. Mastering the command line opens up all sorts of options.

    There's one typo : "For instance, cd edward will switch to a directory called “Edward”
    They both should be edward (or Edward) . Unlike Windows where they're treated identically, in Linux, the filenames are case-sensitive.

    Once you've mastered these commands, check out ssh. It allows you to connect and give commands from any PC by giving you a terminal window that connects over the network, so you don't need a display or keyboard plugged into the Pi. Tis very handy.

    • Christian Cawley
      May 14, 2016 at 8:00 pm

      Unfortunate oversight, thanks for pointing it out!

  10. andycrofts
    April 5, 2014 at 3:51 pm

    @tom g:
    Just get one! Cheap as chips, and EXTREMELY addictive.
    Check mine out.
    oululife.dnsdynamic.com
    and have a look at the PILAB tab, and the drivel I've documented.
    Yeps, the webserver's running on a Pi.
    Cheers, and have shedloads of fun!
    Andy, Oulu, Finland

  11. Jim K
    April 5, 2014 at 6:41 am

    Be careful with Linux based Operating systems cd edward will never change your directory to one called Edward. Linux is case sensitive, cd edward will only switch you to a directory called edward all lower case.

  12. DrToxic
    April 2, 2014 at 10:01 am

    I still don't run the Debian Image on my Pi.
    Risc OS is much faster and easier to code for

    • Christian Cawley
      August 5, 2016 at 8:37 am

      It's a fair point, and there's something poetic about using a Cambridge developed OS with a Cambridge developed device and processor.

      • Eddie
        November 1, 2016 at 4:03 pm

        Used RISC on older large telephone systems in the past (iSDX) !

        Thanks for the information regarding the CLI via SSH

  13. tom g
    April 1, 2014 at 8:56 am

    I so want to get one of these!

  14. Jurmy C
    March 31, 2014 at 6:36 pm

    Useful, thank you.